HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URL's added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using it's URL and the proper URL extention.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
// ===
// === Remember, your browser is someone's oven :D
// ===
//- material
mixin torus(density)
- let n = density % 2 === 0 ? density + 1 : density;
.torus(style=`--n: ${n}`)
- for(let i=0; i<n; i++)
.side(style=`--i: ${i}`)
section(data-camera)
section(data-scene)
section(data-float)
+torus(100)
//- controls
section(data-controls, data-isolated)
input#toggle-rotate(type="checkbox", data-change="rotate")
label(for="toggle-rotate", data-isolated) Rotate
input#toggle-donut-fill(type="checkbox", data-change="donut-fill", checked)
label(for="toggle-donut-fill", data-isolated) Yummy Donut
input#toggle-lights(type="checkbox", data-change="lights", checked)
label(for="toggle-lights", data-isolated) Lighting
input#toggle-glare(type="checkbox", data-change="glare", checked)
label(for="toggle-glare", data-isolated) Glare
input#toggle-sprinkles(type="checkbox", data-change="sprinkles", checked)
label(for="toggle-sprinkles", data-isolated) Sprinkles
input#toggle-pbp(type="checkbox", data-change="pbp")
label(for="toggle-pbp", data-isolated) Preserve Blind Points
input#toggle-outlines(type="checkbox", data-change="outlines")
label(for="toggle-outlines", data-isolated) Outlines
input#toggle-wireframe(type="checkbox", data-change="wireframe")
label(for="toggle-wireframe", data-isolated) Wireframe
input#toggle-gradient-colors(type="checkbox", data-change="gradient-colors")
label(for="toggle-gradient-colors", data-isolated) Gradient Colors
//- hint text
svg.hint(
version="1.1",
viewBox="0 0 35.134 29.888",
xmlns="http://www.w3.org/2000/svg"
)
g.hint-text(transform="translate(-49.388 -131.57)")
g(stroke-dashoffset="16.95")
g(stroke-width="5.0535")
path(
d="m50.788 160.12q-0.25801 0.1339-0.50787 0.13045-0.25286-0.0129-0.45392-0.15625-0.19464-0.15578-0.29042-0.457-0.11803-0.27343-0.14064-0.67048-0.02559-0.40646 0.03353-0.83987 0.06854-0.43639 0.19824-0.77823 0.11643-0.28578 0.24484-0.53391t0.25806-0.36191q0.11381-0.0985 0.2238-0.14369 0.11638-0.0578 0.19153-0.0821 0.16258-0.0103 0.36495 0.0394 0.20879 0.0373 0.2447 0.15022 0 0 0.02779 0.0222 0.03424 0.01 0.03424 0.01 0.05631-0.0184 0.13304 0.0924 0.08598 0.1074 0.14628 0.26444 0.05733 0.14762 0.03375 0.26913 0.01922 0.19082-0.03301 0.35255-0.05223 0.16172-0.12754 0.18566-0.03754 0.0123-0.0724 0.0332-0.02833 9e-3 -0.01326 0.0561 0.01497 0.0471-0.0445 0.0557-0.05011 5e-3 -0.12152-0.0236-0.07446-0.0386-0.12663-0.10486-0.01497-0.0471-0.01323-0.17199 0.0017-0.12494-0.01748-0.31576-0.02733-0.28153-0.11719-0.33588-0.09283-0.0638-0.25721 0.0712-0.19343 0.20662-0.33511 0.51079-0.13226 0.30119-0.19139 0.73459-0.06212 0.42399-0.02672 1.0243 0.01236 0.23447 0.07266 0.3915 0.06966 0.15405 0.10094 0.15448 0.14377-4e-3 0.36367-0.095 0.21696-0.10003 0.30254-0.18945 0.12667-0.1232 0.27602-0.30544 0.14636-0.19165 0.25464-0.34009 0.03808-0.0432 0.08301-0.13011 0.04496-0.0868 0.10826-0.14848 0.03939-0.1369 0.08989-0.17368 0.05048-0.0368 0.16356-0.0725 0.0813-5e-3 0.15917 0.0116 0.07786 0.0167 0.10866 0.0484 0.04022 0.0287-0.0073 0.0748-0.03754 0.0123-0.03811 0.0431 0.0059 0.0188 0.0059 0.0188 0.03081 0.0317-0.03383 0.18696-0.05822 0.1429-0.16393 0.33199-0.10572 0.18909-0.21399 0.33754-0.10185 0.13606-0.15833 0.154-0.09421 0.0298-0.07616 0.0865 6e-3 0.0189-0.11127 0.13904-0.10786 0.11715-0.26275 0.24938-0.14551 0.12915-0.2683 0.19934z"
)
path(
d="m52.972 159.97q-0.10086-0.0557-0.15237-0.11308-0.05151-0.0575-0.05544-0.16602-0.0054-0.14807 0.02838-0.30744 0.03339-0.16925 0.06714-0.32862 0.0133-0.1784 0.03646-0.35715 0.03268-0.18899 0.12566-0.35052 0.09497-0.37905 0.20016-0.74858 0.10484-0.3794 0.17935-0.7775 0.11507-0.36988 0.20375-0.64986 0.09819-0.29021 0.24037-0.73028 0.07988-0.25 0.12908-0.52855 0.0587-0.28877 0.18866-0.52082 0.056-0.091 0.08347-0.1513 0.03697-0.0705 0.07431-0.13119 0.0085-0.0399 0.05744-0.0515 0.05891-0.0116 0.12869 5e-3 0.06981 0.0172 0.11109 0.0651 0.02927-0.0108 0.07125 0.0568 0.05151 0.0575 0.09386 0.13497 0.04235 0.0775 0.03462 0.13713 0.0015 0.0394-0.0158 0.10929-0.0074 0.0695-0.0447 0.13012-0.03805 0.0409-0.07467 0.12133-0.02711 0.0701-0.09155 0.201-0.03483 0.12976-0.05941 0.26904-0.02496 0.12939-0.07037 0.23977-0.03519 0.11989-0.09047 0.23062-0.04542 0.11037-0.06264 0.18019-0.06085 0.22956-0.15169 0.45031-0.08096 0.22038-0.1411 0.46967-0.06049 0.23942-0.12028 0.49858-0.06013 0.24929-0.18023 0.48099-0.06516 0.11109-0.08868 0.27998t-0.04704 0.33776q-0.05278 0.17984-0.0964 0.33958-0.03411 0.1495-0.03267 0.18899-0.05135 0.21931-0.07308 0.43756-0.01222 0.20801-0.08546 0.36882-0.0063 0.0991-0.03375 0.15936-0.02745 0.0604-0.09621 0.0727-0.06909 3e-3 -0.1897-0.0524z"
)
path(
d="m54.305 160.12q-0.07424-0.0835-0.10672-0.20417-0.02261-0.12007-0.0058-0.23782 0.01685-0.11775 0.06091-0.19431 0.0046-0.0789 0.02669-0.11717 0.03248-0.0476 0.02494-0.0876-0.0076-0.04 0.02785-0.13688 0.03539-0.0969 0.0702-0.18387 0.07831-0.15371 0.16997-0.366 0.09224-0.22216 0.17404-0.43503 0.08179-0.21287 0.14039-0.36773 0.05859-0.15488 0.07078-0.19374 7e-3 -0.11832 0.16532-0.1189 0.12065-0.0325 0.17749 0.0104 0.05743 0.033 0.14674 0.19665 0.07424 0.0835 0.04523 0.24014-0.029 0.15661-0.15141 0.38688-0.04408 0.0765-0.11196 0.22098-0.05801 0.14501-0.08469 0.26218-0.04408 0.0765-0.11196 0.22099-0.05743 0.13515-0.10442 0.26101-0.02263 0.0482-0.04815 0.1456-0.02495 0.0876-0.06091 0.1943-0.03539 0.0969-0.08933 0.17285-0.11255 0.39907-0.1955 0.46345-0.07308 0.0649-0.22969-0.13227zm1.1922-3.9471q-0.0464-0.0522-0.08062-0.14328-0.03364-0.10095-0.03886-0.18039-0.0047-0.0893 0.02495-0.0876 0.07947-5e-3 0.19722-0.1566 0.11776-0.15139 0.105-0.27087 0.0023-0.0394 0.03364-0.0672 0.0319-0.0377 0.07192-0.0453 0.12297-0.0719 0.22796-6e-3 0.11542 0.0563 0.20474 0.21986 0.07772 0.19257 0.03073 0.31843-0.04641 0.11601-0.23667 0.3225-0.15952 0.1885-0.28887 0.20068-0.11949 0.0128-0.25115-0.10384z"
)
path(
d="m57.457 160.37q-0.13167 0.0517-0.29872 0.0319-0.16704-0.0198-0.4472-0.13518-0.01973-1e-3 -0.08643-0.0447-0.05685-0.0429-0.12238-0.10618-0.05511-0.0725-0.0899-0.15372-0.14442-0.23608-0.08871-0.67807 0.0557-0.44199 0.3388-1.0487 0.07773-0.14384 0.22914-0.36251 0.16126-0.21809 0.31034-0.39732 0.15952-0.18851 0.22043-0.21461 0 0 0.11079-0.033 0.11079-0.0331 0.28365-0.11194 0.05047-0.0169 0.11079-0.033 0.07018-0.0157 0.13979-0.0214 0.06961-6e-3 0.11833 7e-3 0.19663 0.0216 0.39558 0.17172 0.20939 0.14096 0.33699 0.32658 0.12818 0.17576 0.07133 0.30105-0.0012 0.0197-0.06381 0.0754-0.05221 0.0464-0.12472 0.1015-0.06207 0.0458-0.10442 0.0928-0.05279 0.0563-0.14095 0.0412-0.0783-0.0146-0.14327-0.0876-0.05453-0.0824-0.05741-0.20129-0.01508-0.08-0.1392-0.15661-0.11427-0.0759-0.11427-0.0759-0.07888-5e-3 -0.2355 0.13456-0.14618 0.12992-0.29584 0.319-0.18794 0.16704-0.33065 0.40602-0.14212 0.2291-0.23378 0.44139-0.08121 0.20302-0.11603 0.29003-0.04525 0.0963-0.02614 0.27551 0.01913 0.17923 0.05625 0.22099 0.03828 0.0221 0.19663 0.0216 0.16822-1.2e-4 0.39675-0.0162 0.22912-0.0261 0.44896-0.0626 0.21984-0.0366 0.36137-0.0876 0.19432-0.1073 0.33353-0.11889 0.13921-0.0116 0.20708 0.0122 0.10615 0.0458 0.1218 0.11601 0.01566 0.0702-0.05859 0.15487-0.07366 0.0748-0.24653 0.1537-0.16242 0.0696-0.29641 0.16066-0.12355 0.0818-0.12646 0.13108-0.03944-2e-3 -0.09049 0.0243-0.0406 0.0174-0.06961 6e-3 -0.01973-1e-3 -0.15951 0.0203-0.13979 0.0214-0.29002 0.0521-0.14037 0.0313-0.19141 0.058z"
)
path(
d="m59.821 161.24q-0.07714-0.0342-0.16067-0.12819-0.08294-0.10385-0.13456-0.23551-0.05162-0.13167-0.04524-0.24013 0.05569-0.10557 0.15025-0.36716 0.09514-0.27146 0.23437-0.61948 0.08527-0.10382 0.13342-0.24941 0.05801-0.14501 0.10442-0.26101 0.08817-0.15313 0.21116-0.39326 0.12356-0.24999 0.23726-0.50056 0.12414-0.25986 0.21348-0.4327 0.14386-0.2587 0.24538-0.47041 0.11196-0.22099 0.21406-0.44256 0.11196-0.22099 0.2361-0.48085 0.13458-0.26913 0.26975-0.54812 0.14502-0.27842 0.24712-0.49998 0.11254-0.23085 0.13807-0.3283 0.0046-0.0789 0.03655-0.11659 0.04176-0.0371 0.08121-0.0348 0.04176-0.0371 0.0812-0.0348 0.04003-8e-3 0.07947-5e-3 0.03944 2e-3 0.1392 0.15661 0.10962 0.15488 0.10265 0.27321-0.0093 0.15777-0.1926 0.58236-0.17346 0.42516-0.48206 0.9611-0.37822 0.70995-0.61316 1.1711-0.23436 0.45126-0.32718 0.68327-0.09224 0.22216-0.07426 0.2529 0 0 0.14154-0.0511 0.14211-0.0609 0.30685-0.16993 0.11195-0.0528 0.24536-0.13398 0.13341-0.0812 0.25639-0.15312 0.12355-0.0818 0.2036-0.0969 0.12297-0.0719 0.25523-0.1334 0.13283-0.0713 0.1746-0.10846 0.17227-0.069 0.24942-0.0348 0.08701 0.0348 0.16878 0.15836 0.10092 0.13458 0.02609 0.22912-0.07425 0.0847-0.33992 0.22736-0.21462 0.116-0.52089 0.27607-0.29641 0.16066-0.53133 0.28536-0.22506 0.12528-0.25639 0.15311 0 0 0.07017 0.15256 0.07018 0.15256 0.1421 0.27553 0.06959 0.16241 0.15022 0.30569 0.09106 0.13399 0.08816 0.18329 0.09047 0.31207 0.29928 0.46289 0.20881 0.15083 0.45185 0.0563 0.20186-0.0673 0.28886-0.0325 0.09687 0.0353 0.12934 0.15603 0.0348 0.0812 0.01276 0.1195-0.01162 0.029-0.1369 0.14035-0.19838 0.17633-0.3985 0.21402-0.19026 0.0383-0.34338-0.0499-0.1485 1e-3 -0.35382-0.20884-0.20474-0.21984-0.57826-0.76627 0.0023-0.0394-0.03306-0.11079-0.02493-0.0806-0.06031-0.15197-0.0348-0.0812-0.08874-0.17344-0.05336-0.10211-0.05336-0.10211 0.0023-0.0394-0.02435-0.0905-0.02668-0.0511-0.07192-0.12297-0.15487-0.0586-0.23028 0.0459-0.07541 0.1044-0.16126 0.21808-0.05685 0.12529-0.14967 0.3573-0.08237 0.22273-0.14445 0.43676-0.05221 0.21462-0.03714 0.29466-0.0093 0.15778-0.06208 0.21404-0.05221 0.0464-0.20998 0.0371z"
)
path(
d="m69.339 160.46q-0.25348 0.10382-0.44779 0.0429-0.19373-0.0708-0.29987-0.28482-0.09628-0.21347-0.0777-0.529 0.0064-0.10847 0.04874-0.32367 0.05221-0.21461 0.11545-0.44837 0.06382-0.24361 0.13343-0.41762 0.0348-0.087 0.04757-0.13572 0.02263-0.0482-0.01682-0.0505-0.03944-2e-3 -0.10151 0.0435-0.05221 0.0464-0.08353 0.0742-0.22738 0.16472-0.47914 0.40716-0.24189 0.24303-0.45478 0.49765-0.21231 0.24478-0.35327 0.45417-0.1311 0.20996-0.1369 0.30857-0.0087 0.14791-0.1601 0.19837-0.1514 0.0505-0.25579-0.0251-0.18097-0.11949-0.22156-0.27031-0.03015-0.1601 0.02089-0.5232 0.05686-0.46171 0.12765-0.82366 0.07078-0.36193 0.20421-0.77956 0.14387-0.42691 0.3678-1.0371 0.14851-0.33757 0.27497-0.63687 0.12704-0.30916 0.2187-0.52145 0.10152-0.21171 0.12414-0.25985 0.05221-0.0464 0.14212-0.22911 0.09049-0.19257 0.16127-0.3863 0.08063-0.19315 0.08295-0.23259 0.0046-0.0789 0.03771-0.13631 0.03365-0.0673 0.07541-0.10441 0.04176-0.0371 0.07308-0.0649t0.03132-0.0278q0.04931 3e-3 0.11659 0.0365 0.07714 0.0342 0.14268 0.0975 0.06612 0.0534 0.0812 0.13341 0.06089 0.14212 0.05219 0.29002-0.0081 0.13805-0.10907 0.33991-0.09107 0.20242-0.30977 0.55566-0.17577 0.29639-0.32311 0.61424-0.14735 0.31786-0.28658 0.66588-0.05801 0.14501-0.16243 0.40603-0.09456 0.26159-0.20014 0.54232-0.09572 0.28132-0.16824 0.50463-0.06208 0.21404-0.06556 0.27319-0.0041 0.0691 0.07482 0.0737 0.07947-5e-3 0.16474-0.10905 0.04409-0.0765 0.17924-0.18734 0.13516-0.11078 0.21811-0.17516 0.08295-0.0643 0.22855-0.18444 0.1456-0.12007 0.31092-0.23897 0.1659-0.12876 0.30917-0.20938 0.14386-0.0905 0.22274-0.0859 0.12819 8e-3 0.23085 0.11257 0.10324 0.0951 0.1363 0.20592 0.02784 0.0313 0.05452 0.0823 0.02726 0.0412 0.03596 0.0615 0.04698 0.0423-0.02032 0.34512-0.05686 0.2935-0.2425 0.75753-0.11023 0.35961-0.18448 0.61252-0.06382 0.24361 0.01506 0.24825 0 0 0.1021-0.0534 0.11195-0.0528 0.23434-0.11484 0.29699-0.17051 0.50581-0.1879 0.21926-0.0267 0.21287 0.0817-0.0023 0.0394-0.03422 0.0771-0.03132 0.0278-0.03364 0.0672 0 0-5.88e-4 0.01 0 0-0.0023 0.0394-0.0012 0.0198-0.13748 0.15023-0.13574 0.12064-0.30163 0.24941-0.15546 0.11948-0.24536 0.13397z"
)
path(
d="m71.107 161.46q-0.43387-0.0256-0.69081-0.36721-0.25636-0.35151-0.21747-0.84397 0.04062-0.35382 0.18275-0.75115 0.15257-0.4066 0.38171-0.76911 0.22972-0.37239 0.49307-0.64383 0.26335-0.27145 0.53656-0.3741 0.10151-0.0435 0.21172-0.0667 0.12007-0.0226 0.2384-0.0156 0.10847 6e-3 0.22447 0.0528 0.11659 0.0365 0.19315 0.0806 0.16357 0.0788 0.24651 0.18272 0.08294 0.10386 0.13977 0.31497 0.01855 0.1891 0.0139 0.26798-0.0046 0.0789-0.06324 0.23376-0.13923 0.34802-0.34168 0.59336-0.20245 0.24535-0.52844 0.40427-0.08179 0.0447-0.192 0.0678-0.09977 0.0139-0.20823 7e-3 -0.19722-0.0116-0.38051-0.0916-0.17285-0.0893-0.27261-0.24363l-0.06438-0.0829-0.03422 0.0771q-0.11428 0.26044-0.1868 0.48375-0.06266 0.2239-0.07369 0.41124-7e-3 0.11834 0.0064 0.22796 0.02319 0.11021 0.06785 0.192 0.03596 0.0615 0.12296 0.0963 0.09745 0.0256 0.20591 0.032 0.06902 4e-3 0.13805 8e-3 0.07947-5e-3 0.15023-0.0307 0.17112-0.0493 0.27378-0.11251 0.11253-0.0626 0.22564-0.13513l0.0406-0.0174-0.0099-5.9e-4q0.12181-0.0522 0.21404-0.10613 0.10209-0.0534 0.10209-0.0534 0.03944 2e-3 0.08179-0.0447 0.0812-0.0348 0.19547 0.0412 0.12413 0.0765 0.11774 0.18503-0.01279 0.0487-0.09803 0.15255-0.08469 0.094-0.18852 0.1769-0.09397 0.0835-0.15372 0.0899-0.01047 9e-3 -0.07134 0.0354-0.06033 0.0162-0.0812 0.0348l0.0099 5.8e-4q-0.09571 0.1131-0.18446 0.10788l-0.07888-5e-3q-0.0435 0.0667-0.26567 0.14268-0.22158 0.0661-0.42865 0.0539zm0.57145-2.1432q0.17749 0.0104 0.31149-0.0806 0.14444-0.10034 0.25059-0.22272 0.21289-0.25463 0.25698-0.4994 0.05454-0.25406-0.03827-0.35847-0.05743-0.033-0.10673-0.0359-0.03885-0.0123-0.16937 0.0197-0.0899 0.0144-0.25522 0.1334-0.16532 0.1189-0.33238 0.26738-0.1572 0.14907-0.24247 0.25289l-0.14038 0.19952q0.08062-0.0249 0.14965-0.0208 0.07947-5e-3 0.08816 0.0152-0.0052 0.0888 0.01971 0.16937 0.03538 0.0713 0.08236 0.1137 0.05685 0.0429 0.12587 0.047z"
)
path(
d="m73.873 161.36q-0.05511 0.0957-0.1514 0.0505-0.08643-0.0447-0.14327-0.0876-0.06902-4e-3 -0.11601-0.0464-0.04698-0.0423-0.06205-0.1224-0.01624-0.0604-0.0018-0.13862 0.01511-0.0882 0.05105-0.1949 0.04641-0.116 0.09398-0.25173 0.09804-0.32076 0.13633-0.46692 0.03829-0.14618 0.07426-0.25291 0.03596-0.10672 0.09746-0.3109 0.09049-0.19256 0.15083-0.37701 0.06034-0.18446 0.16997-0.366 0.08411-0.25232 0.19608-0.4733 0.1224-0.23027 0.2303-0.38225 0.02147-0.0284 0.07366-0.0748 0.06207-0.0458 0.10151-0.0435 0.08353-0.0742 0.14154-0.0511 0.06843 0.014 0.16241 0.0986 0.11078 0.13516 0.07133 0.30104-0.0296 0.16647-0.26568 0.47911-0.13632 0.29871-0.24828 0.5197-0.11138 0.21113-0.16243 0.40602 0.11776-0.15138 0.25349-0.27202 0.14618-0.12993 0.24015-0.21345 0.22971-0.20416 0.37356-0.29464 0.15372-0.0899 0.35848-0.20648 0.12297-0.0719 0.23492-0.1247 0.11253-0.0626 0.24246-0.0847 0.13979-0.0214 0.29582 0.0174 0.0992-4e-3 0.15429 0.0685 0.06496 0.073 0.09744 0.19374 0.03248 0.12065 0.03305 0.279-0.22389-0.0627-0.40545-4e-3 -0.18098 0.0487-0.31439 0.12991-0.12355 0.0818-0.19548 0.12702-0.15372 0.0899-0.39038 0.24418-0.23608 0.14442-0.47623 0.35786-0.1891 0.18677-0.32542 0.31727-0.12646 0.13109-0.21173 0.23491-0.07541 0.10441-0.12182 0.22041-0.11196 0.22099-0.2361 0.48084-0.12414 0.25986-0.20651 0.31437z"
)
path(
d="m77.621 161.04q-0.37528-0.18042-0.47735-0.46348-0.09163-0.29234 0.01223-0.87993 0.03772-0.30452 0.04353-0.40312 0.0058-0.0986-0.09686-0.2036-0.02726-0.0412-0.10208-0.11486-0.06496-0.073-0.0522-0.12181-0.0058-0.0696 0.01859-0.14733 0.02495-0.0876 0.06439-0.0853 0.03944 2e-3 0.08004-0.015 0.05047-0.0169 0.08875 5e-3 0.03944 2e-3 0.08816 0.0152 0.04872 0.0129 0.0464 0.0522 0.03538 0.0713 0.12702 0.0273 0.09223-0.054 0.20245-0.24535 0.1079-0.15197 0.27496-0.30044 0.17692-0.1479 0.34224-0.26681 0.17576-0.12817 0.28771-0.18096 0.05047-0.0169 0.15081-0.0406 0.10035-0.0238 0.20998-0.0371 0.11949-0.0127 0.1978 2e-3 0.1769 0.0204 0.29001 0.11605 0.12296 0.0963 0.22447 0.221 0.12296 0.0963 0.14384 0.24595 0.03073 0.15024 0.0011 0.31671-0.02959 0.16647-0.10674 0.30045-0.03538 0.0969-0.18156 0.22679-0.14618 0.12993-0.33122 0.24767-0.18504 0.11773-0.33643 0.16818-0.12993 0.022-0.33817 0.0296-0.19838 8e-3 -0.37587-2e-3 -0.16704-0.0198-0.22448-0.0528-0.0667-0.0435-0.11485 0.10208-0.04815 0.14559-0.08413 0.42053-0.03249 0.21577-0.01858 0.31554 0.01392 0.0998 0.03131 0.14037 0.06496 0.0731 0.1769 0.18852 0.12238 0.10617 0.35325 0.0505 0.19026-0.0383 0.37994-0.2349 0.19955-0.19605 0.36486-0.31495 0.0435-0.0667 0.13283-0.0713 0.09977-0.014 0.20649 0.0222 0.10441 0.0754 0.07888 0.17285-0.01511 0.0882-0.11486 0.2703-0.03364 0.0672-0.1485 0.16936-0.10442 0.0928-0.23899 0.19372-0.12414 0.0917-0.22622 0.145-0.30511 0.14036-0.56207 0.13513-0.25638-0.0151-0.48781-0.11778zm0.69963-1.9675q0.21984-0.0365 0.34918-0.0487 0.12935-0.0122 0.2529-0.0939 0.12414-0.0917 0.3173-0.34743 0.04583-0.10614 0.0325-0.21577-0.0035-0.10905-0.0406-0.15082-0.08294-0.10386-0.21345-0.072-0.12007 0.0226-0.23318 0.0951-0.07076 0.0255-0.21578 0.13572-0.13458 0.10093-0.27147 0.24128-0.13632 0.13051-0.22217 0.24419-0.08585 0.11369-0.04757 0.13573-0.02205 0.0383 0.10556 0.0557 0.13746 0.0181 0.18676 0.021z"
)
path.special-arrow(
d="m77.944 139.13c0.03222-0.0695 0.06795-0.13739 0.09667-0.20837 0.10368-0.25626 0.2867-0.7904 0.35946-1.0111 0.27499-0.83425 0.51672-1.6785 0.76169-2.5219 0.07787-0.27851 0.15677-0.55674 0.23363-0.83553 0.1315-0.47697 0.25478-0.95618 0.38644-1.4331 0.07986-0.28929 0.18908-0.6822 0.29789-0.97166 0.03726-0.0991 0.08493-0.19403 0.1274-0.29104 0.0462-0.0432 0.07715-0.11462 0.1386-0.12975 0.1322-0.0322 0.35776 0.21623 0.39525 0.261 0.11338 0.13541 0.20915 0.28472 0.30832 0.43085 0.30041 0.44268 0.5239 0.81609 0.80797 1.2754 0.77964 1.279 1.5625 2.5559 2.37 3.8176 0.09596 0.1613 0.25327 0.0677 0.15724-0.0937-0.73221-1.3097-1.4818-2.6108-2.3001-3.8691-0.30662-0.4479-0.548-0.82671-0.8951-1.2397-0.15306-0.1821-0.56861-0.70776-0.89876-0.62482-0.0751 0.0187-0.12407 0.0926-0.18608 0.13892-0.05659 0.0971-0.11988 0.19048-0.16977 0.29114-0.14612 0.29481-0.27668 0.66288-0.37958 0.96925-0.25067 0.7463-0.46156 1.5056-0.69049 2.2586-0.357 1.2497-0.69784 2.5042-0.94242 3.7817-0.0054 0.0223 0.01626 0.0275 0.0217 6e-3z",
stroke-width=".21422"
)
path(
d="m80.841 134.99c0.0049 0.0292 0.0098 0.0584 0.01461 0.0876 0.01168 0.0869 0.02123 0.1741 0.03496 0.26067 0.08471 0.53337 0.10118 0.44931 0.14482 1.096 0.04622 0.68491 0.04743 1.5072 0.05708 2.1839-0.1499 1.4057-0.15022 1.7001-0.43851 3.131-0.11508 0.57122-0.22139 1.1466-0.39486 1.7029-0.27331 0.87636-1.0005 2.3912-1.4549 3.1442-0.31984 0.53005-0.70783 1.0158-1.0618 1.5238-1.0494 1.3163-2.2554 2.4948-3.5766 3.536-0.3481 0.27431-0.71567 0.52295-1.0735 0.78442-0.57321 0.28643-0.29384 0.84549 0.27936 0.55906 0.3857-0.24041 0.78285-0.46336 1.1571-0.72124 1.4373-0.99041 2.7256-2.1702 3.8306-3.5229 0.97005-1.3764 1.3551-1.7683 2.0201-3.3274 0.27785-0.65143 0.50844-1.3242 0.69967-2.0061 0.26304-0.93778 0.48124-2.46 0.54143-3.439 0.03095-0.50255 0.0062-1.007 0.0092-1.5105-0.04049-0.39776-0.06582-0.79736-0.12148-1.1933-0.11088-0.7886-0.30142-1.5791-0.65377-2.2967-0.0075-0.0138-0.02112-6e-3 -0.01352 7e-3z"
)
/*
* 20 January 2022
* CSS 3D Donut
* โ responsive, โ rotate (XZ), โ pan (XYZ)
* โ 9 toggles, 81 possible appearances
* mvp: 100 DIVs, 104 pseudo-elements, CSS gradients, mask and chained transforms
* requires: the latest version of Firefox and Chrome
*/
:root {
// === scene configuration ===
--rotate-duration: 10s;
--drop-shadow: rgba(0, 0, 0, 0.7);
--ambient-light: rgba(0, 0, 0, 0.5);
// === attr-toggle CSS configuration ===
--accent: #488cfb;
--accent-background: #31384d;
--text: #fff;
--text-secondary: rgba(255, 255, 255, 0.7);
--controls-padding: 2vmin;
--controls-transition-duration: 300ms;
--controls-font-size: max(14px, 2.2vmin);
--controls-line-opacity: 0.4;
--controls-line-padding: 30%;
--controls-line-height: 0.72em;
--controls-margin-inline: 0.6em;
--controls-margin-block: 0.8em;
}
// === camera configuration ===
[data-camera] {
--cameraY: 41;
}
// === our subject material ===
.torus {
--radius: 200;
--thickness: 131;
--border-width: 15;
--color: #488cfb;
--outline-color: #000;
--sprinkle-color: #f7f7f770;
--sprinkle-scale: 0.8;
--sprinkle-mass: 12;
--glare-mass: 53;
position: absolute;
left: 50%;
top: 50%;
transform: translate(-50%, -50%);
}
// === toggles ===
// * === toggles: "Gradient Colors" ===
body:not([data-gradient-colors]) .torus {
--gradient-colors: none;
}
body[data-gradient-colors] #toggle-donut-fill + label {
opacity: 0.4;
pointer-events: none;
}
// * === toggles: "Yummy Donut" ===
body[data-donut-fill] {
--accent: hsl(23, 65%, 53%);
--text: hsl(36, 79%, 92%);
--text-secondary: hsla(36, 79%, 88%, 0.7);
// --outline: 0 0 0 1px hsl(23, 66%, 45%);
& .torus {
--gradient-colors: linear-gradient(
hsl(36, 79%, 84%),
hsl(32, 67%, 56%) 62%,
hsl(23, 65%, 53%) 77%
);
--color: #3a6eeba3;
}
&[data-gradient-colors] {
--accent: #488cfb;
--text: #fff;
--text-secondary: rgba(255, 255, 255, 0.7);
& .torus {
--gradient-colors: var(--default-gradient-colors);
}
}
}
// * === toggles: "Outlines" ===
body:not([data-outlines]) .torus {
--outline: none;
}
// * === toggles: "Wireframe" ===
body[data-wireframe] .torus {
--m-image: linear-gradient(#000 0 0);
--border-width: 3;
}
// * === toggles: "Preserve Blind Points" ===
body[data-pbp] .torus {
--y-base: 98;
}
// * === toggles: "Lighting" ===
body[data-lights] .torus {
--inner-shade-color: var(--ambient-light);
}
body:not([data-lights]) .torus {
--lights: none;
}
// * === toggles: "Glare" ===
body:not([data-glare]) .torus {
--glare-images: none;
--glare-points: 0 0;
--glare-size: 0 0;
}
// * === toggles: "Sprinkles" ===
body:not([data-sprinkles]) .torus::before {
content: none;
}
// * === toggles: "Rotate" ===
body[data-rotate] [data-float] {
animation-play-state: running;
}
body {
// === add a drop shadow for realism ===
filter: drop-shadow(
calc(13 * var(--px)) calc(13 * var(--px)) calc(17 * var(--px))
var(--drop-shadow)
);
// === the mask-image is disabled by default as it makes the object resource-intensive and drops fps ===
& .torus {
--m-image: none;
}
}
// === scene defaults ===
label {
transition-property: color, opacity;
}
html::before {
background-image: radial-gradient(
circle at 50% 50%,
var(--accent-background),
#000
);
}
[data-scene] {
background-color: transparent;
}
[data-float] {
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
transform: rotateX(0turn) rotateY(0turn) rotateZ(0turn);
animation: rotate linear var(--rotate-duration) forwards infinite;
animation-play-state: paused;
transform-style: preserve-3d;
}
@keyframes rotate {
to {
transform: rotateX(1turn) rotateY(2turn) rotateZ(3turn);
}
}
// === decoration ===
@function rand($min, $max) {
@return $min + math.random() * ($max - $min);
}
@function place-backgrounds($n, $quadrant: 1, $start: 1, $sprinkle: null) {
$points: null;
$one-fourth: 0.5 * math.$pi;
$theta: devide($quadrant * $one-fourth, $n);
@for $i from 1 through $n {
$angle: ($theta * $i) + $one-fourth * ($start - 2);
$multiplier: rand(0.98, 1.2);
@if $sprinkle == 1 {
$multiplier: rand(0.8, 1);
}
$x: calc(50% + 50% * #{math.cos($angle) * $multiplier});
$y: calc(50% + 50% * #{math.sin($angle) * $multiplier});
$points: $points, $x $y;
}
@return $points;
}
@function repeat($n, $value) {
$values: null;
@for $i from 1 through $n {
$values: $values, $value;
}
@return $values;
}
// === torus geometry ===
@mixin torus {
$glare-density: 8;
$sprinkle-density: 200;
--default-outline: 0 0 0 1px var(--outline-color, #000);
--default-lights: linear-gradient(
to right,
transparent,
var(--inner-shade-color, transparent)
);
--default-gradient-colors: conic-gradient(
hsl(217, 96%, 63%),
hsl(170, 71%, 51%),
hsl(66, 96%, 49%),
hsl(36, 100%, 53%),
hsl(315, 75%, 57%),
hsl(245, 65%, 61%),
hsl(217, 96%, 63%)
);
--default-glare-color: rgba(255, 255, 255, 0.13);
--calc-border-width: calc(var(--border-width) * var(--px));
--calc-diameter: calc(var(--radius) * 2 * var(--px));
--calc-thickness: calc(var(--thickness) * var(--px));
--calc-half-thickness: calc(((var(--thickness) * 0.5) - 4) * var(--px));
--calc-distance: calc((var(--radius) - (var(--thickness) * 0.5)) * var(--px));
--calc-reverse-distance: calc(
(var(--radius) - (var(--thickness) * 0.5)) * -2 * var(--px)
);
--calc-glare-mass: calc(var(--glare-mass) * var(--px));
--calc-sprinkle-mass: calc(var(--sprinkle-mass) * var(--px));
--glare-image: radial-gradient(
circle at center,
var(--glare-color, var(--default-glare-color)) 50%,
transparent calc(50% + 1px)
);
--glare-images: #{repeat($glare-density, var(--glare-image))};
--glare-points: #{place-backgrounds($glare-density, 1, -1)};
--glare-size: #{repeat(
$glare-density,
var(--calc-glare-mass) var(--calc-glare-mass)
)};
--m-image: linear-gradient(#000 0 0);
--m-origin: content-box, padding-box;
width: var(--calc-diameter);
height: var(--calc-diameter);
&::before {
content: "";
position: absolute;
left: 50%;
top: 50%;
width: 100%;
height: 100%;
border-radius: 50%;
transform: translate(-50%, -50%) translateZ(var(--calc-half-thickness))
scale(var(--sprinkle-scale));
--sprinkle-image: radial-gradient(
circle at center,
var(--sprinkle-color) 50%,
transparent calc(50% + 1px)
);
--sprinkle-images: #{repeat($sprinkle-density, var(--sprinkle-image))};
--sprinkle-points: #{place-backgrounds($sprinkle-density, 4, 0, 1)};
--sprinkle-size: #{repeat(
$sprinkle-density,
var(--calc-sprinkle-mass) var(--calc-sprinkle-mass)
)};
background-image: var(--sprinkle-images);
background-position: var(--sprinkle-points);
background-size: var(--sprinkle-size);
background-repeat: no-repeat;
}
&,
& .side {
transform-style: preserve-3d;
}
& .side {
--angle: calc((var(--i) / var(--n)) * 1turn);
position: absolute;
left: 50%;
top: 50%;
width: var(--calc-thickness);
height: var(--calc-thickness);
transform: translate(-50%, -50%) rotateZ(var(--angle))
rotateX(calc(var(--y-base, 90) * 1deg)) translateX(var(--calc-distance));
box-shadow: var(--outline, var(--default-outline));
border-radius: 50%;
&::before,
&::after {
content: "";
position: absolute;
left: 0;
top: 0;
width: 100%;
height: 100%;
border-radius: 50%;
padding: var(--calc-border-width);
transform: scaleX(-1);
background-color: var(--color, #000);
background-image: var(--glare-images), var(--lights, var(--default-lights)),
var(--gradient-colors, var(--default-gradient-colors));
background-position: var(--glare-points), 0 0, 0 0;
background-size: var(--glare-size), 100% 100%, 100% 100%;
background-repeat: no-repeat;
mask-image: var(--m-image), var(--m-image);
-webkit-mask-image: var(--m-image), var(--m-image);
mask-origin: var(--m-origin);
-webkit-mask-origin: var(--m-origin);
mask-clip: var(--m-origin);
-webkit-mask-clip: var(--m-origin);
mask-composite: exclude;
-webkit-mask-composite: destination-out;
}
&::before {
transform: translateX(var(--calc-reverse-distance));
}
}
}
.torus {
@include torus;
}
/*
* ====
* ==== Frequently asked questions ====
* ====
*
* [1]. What is the Camera class?
* ans: The `Camera` class is a custom API and a part of the control system that I'm using to enable user interaction such as "drag to rotate" and "pan"
*
* [2]. Gotcha! aren't you using JavaScript to do this?! ๐
* ans: Apparently, I am. But I should clarify that the controller API has nothing to do with the 3D creation itself. It only updates CSS variables, namely `--camera*` based on mouse movements and touch gestures. The 3D structure you are seeing is entirely CSS.
*
* [3]. Nah, I disagree. You aren't using pure CSS. You're using Sass ๐
* ans: ๐คฆโโ๏ธ Ah, man! Sass is a CSS compiler. I am particularly using the SCSS syntax. I'm writing SCSS instead of CSS to minimize repetition. You see, the nested structure keeps the code tidy and saves me from repeating the same code over and over. The compiled code is still pure CSS and with built-in CSS variables.
*
* [4]. Oh ๐ณ ... okay. Soo, what's that "attrToggle" thing? ๐คจ
* ans: Another part of the controller API. It "toggles" certain attributes/classes to customize the 3D creation dynamically.
*
* [5]. Cool! Do you have any plans to make the controller API public? ๐
* ans: I would love to. The API is still experimental due to a lack of testing suite and developer force. I have been busy with my college stuff, so I can't work on it any time soon.
*
* [6]. Thanks for the conversation! Where can I find you later? ๐
* ans: Maybe on Twitter? ๐ DMs always open: @ShadowShahriar
*
*/
window.addEventListener("load", () => {
new Camera()
.setOptimalPerspective()
.with({
debug: true,
rotate: {
speed: 1.2
}
})
.init();
new attrToggle("[data-controls]").init();
});
Also see: Tab Triggers