Files
30-seconds-of-code/snippets/donut-spinner.md
2018-02-28 18:24:33 +10:00

1.3 KiB

Donut spinner

Creates a donut spinner that can be used to indicate the loading of content.

HTML

<div class="donut"></div>

CSS

@keyframes donut-spin {
  0% { transform: rotate(0deg); }
  100% { transform: rotate(360deg); }
}
.donut {
  display: inline-block;
  border: 4px solid rgba(0, 0, 0, 0.25);
  border-left-color: blue;
  border-radius: 50%;
  width: 20px;
  height: 20px;
  animation: donut-spin 1.2s linear infinite;
}

Demo

<style> @keyframes snippet-demo__donut-spin { 0% { transform: rotate(0deg); } 100% { transform: rotate(360deg);} } .snippet-demo__donut-spinner { display: inline-block; border: 4px solid rgba(0, 0, 0, 0.25); border-left-color: blue; border-radius: 50%; width: 20px; height: 20px; animation: snippet-demo__donut-spin 1.2s linear infinite; } </style>

Explanation

Use a semi-transparent border for the whole element, except one side that will serve as the loading indicator for the donut. Use animation to rotate the element.

Browser support

⚠️ Requires prefixes for full support.