@keyframes defines an animation that has two states, where the element changes opacity and is translated up on the 2D plane using transform: translateY().
+
@keyframes defines an animation that has two states, where the element changes opacity and is translated up on the 2D plane using transform: translate3d(). Using a single axis translation on transform: translate3d() improves the performance of the animation.
-
.bouncing-loader is the parent container of the bouncing circles and uses display: flex and justify-content: center to position them in the center.
+
.bouncing-loader is the parent container of the bouncing circles and uses display: flex
+ and justify-content: center to position them in the center.
-
.bouncing-loader > div, targets the three child divs of the parent to be styled. The divs are given a width and height of 1rem, using border-radius: 50% to turn them from
- squares to circles.
+
.bouncing-loader > div, targets the three child divs of the parent to be styled. The divs are given a width and height of 1rem, using border-radius: 50% to turn them from squares to circles.
-
margin: 3rem 0.2rem specifies that each circle has a top/bottom margin of 3rem and left/right margin of 0.2rem so that they do not directly touch each other, giving them some breathing room.
+
margin: 3rem 0.2rem specifies that each circle has a top/bottom margin of 3rem and left/right margin
+ of 0.2rem so that they do not directly touch each other, giving them some breathing room.
animation is a shorthand property for the various animation properties: animation-name, animation-duration, animation-iteration-count, animation-direction are used.
This effect is uses before and after selectors to make the border full width on hover.
-
Browser support
-
-
- 99+%
-
-
-
✅ No caveats.
-
-
-
-
-
Calc()other
The function calc() allows to define CSS values with the use of mathematical expressions, the value adopted for the property is the result of a mathematical expression.
@@ -455,46 +254,43 @@
-
-
If you want to align a background-image from right and bottom wasn't possible with just straight length values. So now it's possible using calc():
+
+
If you want to align a background-image from right and bottom wasn't possible with just straight length values.
+ So now it's possible using calc():
It allows addition, subtraction, multiplication and division.
Can use different units (pixel and percent together, for example) for each value in your expression.
It is permitted to nest calc() functions.
-
It can be used in any property that <length>, <frequency>, <angle>, <time>, <number>, <color>, or <integer> is allowed, like width, height, font-size, top, left, etc.
+
It can be used in any property that <length>, <frequency>, <angle>, <time>, <number>, <color>, or <integer> is allowed, like width, height, font-size, top, left, etc.
content: '' allows the pseudo-element to affect layout.
-
clear: both indicates that the left, right or both sides of the element cannot be adjacent to earlier floated elements within the same block formatting context.
+
clear: both indicates that the left, right or both sides of the element cannot be adjacent
+ to earlier floated elements within the same block formatting context.
Browser support
@@ -596,7 +387,8 @@
Constant width to height ratiolayout
-
Given an element of variable width, it will ensure its height remains proportionate in a responsive fashion (i.e., its width to height ratio remains constant).
+
Given an element of variable width, it will ensure its height remains proportionate in a responsive fashion
+ (i.e., its width to height ratio remains constant).
padding-top on the ::before pseudo-element causes the height of the element to equal a percentage of its width. 100% therefore means the element's height will always be 100% of the width,
- creating a responsive square.
-
+
padding-top on the ::before pseudo-element causes the height of the element to equal a percentage of
+ its width. 100% therefore means the element's height will always be 100% of the width, creating a responsive
+ square.
This method also allows content to be placed inside the element normally.
Browser support
@@ -688,47 +476,40 @@ li::before {
-
+
Explanation
You can create a ordered list using any type of HTML.
-
counter-reset Initializes a counter, the value is the name of the counter. By default, the counter starts in 0. This property can also be used to change its value to any specific number.
+
counter-reset Initializes a counter, the value is the name of the counter. By default, the counter starts at 0. This property can also be used to change its value to any specific number.
counter-increment Used in element that will be countable. Once counter-reset initialized, a counter's value can be increased or decreased.
-
counter(name, style) Displays the value of a section counter. Generally used in a content property. This function can receive two parameters, the first as the name of the counter and the second one can be decimal or upper-roman (decimal by default).
+
counter(name, style) Displays the value of a section counter. Generally used in a content property. This function can receive two parameters, the first as the name of the counter and the second one can be decimal or upper-roman (decimal by default).
-
counters(counter, string, style) Displays the value of a section counter. Generally used in a content property. This function can receive three parameters, the first as the name of the counter, the second one
- you can include a string which comes after the counter and the third one can be decimal or upper-roman (decimal by default).
+
counters(counter, string, style) Displays the value of a section counter. Generally used in a content property. This function can receive three parameters, the first as the name of the counter, the second one you can include a string which comes after the counter and the third one can be decimal or upper-roman (decimal by default).
-
A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the counters() function, separating text can be inserted between different
- levels of nested counters.
+
A CSS counter can be especially useful for making outlined lists, because a new instance of the counter is automatically created in child elements. Using the counters() function, separating text can be inserted between different levels of nested counters.
Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.
HTML
<div class="custom-scrollbar">
<p>
- Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>
- Iure id exercitationem nulla qui repellat laborum vitae, <br>
- molestias tempora velit natus. Quas, assumenda nisi. <br>
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />
+ Iure id exercitationem nulla qui repellat laborum vitae, <br />
+ molestias tempora velit natus. Quas, assumenda nisi. <br />
Quisquam enim qui iure, consequatur velit sit?
</p>
</div>
@@ -766,52 +547,43 @@ li::before {
- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit?
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.
+ Iure id exercitationem nulla qui repellat laborum vitae,
+ molestias tempora velit natus. Quas, assumenda nisi.
+ Quisquam enim qui iure, consequatur velit sit?
-
+
Explanation
::-webkit-scrollbar targets the whole scrollbar element.
::-webkit-scrollbar-track targets only the scrollbar track.
::-webkit-scrollbar-thumb targets the scrollbar thumb.
-
There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the
- WebKit Blog.
+
There are many other pseudo-elements that you can use to style scrollbars. For more info, visit the WebKit Blog.
Browser support
- 88.0%
+ 86.7%
⚠️ Scrollbar styling doesn't appear to be on any standards track.
::selection defines a pseudo selector on an element to style text within it when selected. Note that if you don't combine any other selector your style will be applied at document root level, to any selectable element.
Browser support
- 84.9%
+ 82.5%
⚠️ Requires prefixes for full support and is not actually
in any specification.
The variables are defined globally within the :root CSS pseudo-class which matches the root element of a tree representing the document. Variables can also be scoped to a selector if defined within the block.
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.
+
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.
Variables that can be reused for transition-timing-function properties, more powerful than the built-in ease, ease-in, ease-out and ease-in-out.
+
Variables that can be reused for transition-timing-function properties, more
+ powerful than the built-in ease, ease-in, ease-out and ease-in-out.
HTML
<div class="easing-variables">Hover</div>
CSS
:root {
@@ -1218,57 +954,50 @@ in any specification.
Hover
-
+
Explanation
-
The variables are defined globally within the :root CSS pseudo-class which matches the root element of a tree representing the document. In HTML, :root represents the <html> element and is identical
- to the selector html, except that its specificity is higher.
+
The variables are defined globally within the :root CSS pseudo-class which matches the root element of a tree representing the document. In HTML, :root represents the <html> element and is identical to the selector html, except that its specificity is higher.
Changes the fit and position of an image within its container while preserving its aspect ratio. Previously only possible using a background image and the background-size property.
transition: max-height: 0.5s cubic-bezier(...) specifies that changes to max-height should be transitioned over 0.5 seconds, using an ease-out-quint timing function.
overflow: hidden prevents the contents of the hidden element from overflowing its container.
max-height: 0 specifies that the element has no height initially.
-
.target:hover > .el specifies that when the parent is hovered over, target a child .el within it and use the --max-height variable which was defined by JavaScript.
+
.target:hover > .el specifies that when the parent is hovered over, target a child .el within
+ it and use the --max-height variable which was defined by JavaScript.
JavaScript
-
el.scrollHeight is the height of the element including overflow, which will change dynamically based on the content of the element.
+
el.scrollHeight is the height of the element including overflow, which will change dynamically
+ based on the content of the element.
el.style.setProperty(...) sets the --max-height CSS variable which is used to specify the max-height of the element the target is hovered over, allowing it to transition smoothly from 0 to auto.
display: inline-block to set width and length for p element thus making it an inline-block.
+
Set transform: perspective(1px) to give element a 3D space by affecting the distance between the Z plane and the user and translate(0) to reposition the p element along z-axis in 3D space.
+
box-shadow: to set up the box.
+
transparent to make box transparent.
+
transition-property to enable transitions for both box-shadow and transform.
+
:hover to activate whole css when hovering is done until active.
+
transform: scale(1.2) to change the scale, magnifying the text.
display: inline-block makes the block p an inline-block to prevent the underline from spanning the entire parent width rather than just the content (text).
+
display: inline-block makes the block p an inline-block to prevent the underline from
+ spanning the entire parent width rather than just the content (text).
position: relative on the element establishes a Cartesian positioning context for pseudo-elements.
::after defines a pseudo-element.
position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
width: 100% ensures the pseudo-element spans the entire width of the text block.
transform: scaleX(0) initially scales the pseudo element to 0 so it has no width and is not visible.
bottom: 0 and left: 0 position it to the bottom left of the block.
-
transition: transform 0.25s ease-out means changes to transform will be transitioned over 0.25 seconds with an ease-out timing function.
+
transition: transform 0.25s ease-out means changes to transform will be transitioned over 0.25 seconds
+ with an ease-out timing function.
transform-origin: bottom right means the transform anchor point is positioned at the bottom right of the block.
-
:hover::after then uses scaleX(1) to transition the width to 100%, then changes the transform-origin to bottom left so that the anchor point is reversed, allowing it transition out in the
- other direction when hovered off.
+
:hover::after then uses scaleX(1) to transition the width to 100%, then changes the transform-origin
+ to bottom left so that the anchor point is reversed, allowing it transition out in the other direction when
+ hovered off.
This effect is uses before and after selectors to make the border full width on hover.
-
Browser support
-
-
- 99+%
-
-
-
✅ No caveats.
-
-
-
-
-
-
-
Last item with remaining available heightlayout
Take advantage of available viewport space by giving the last element the remaining available space in current viewport, even when resizing the window.
HTML
<div class="container">
@@ -1913,22 +1586,18 @@ body {
Div 3
-
+
Explanation
height: 100% set the height of container as viewport height.
A bulletproof way to completely hide an element visually and positionally in the DOM while still allowing it to be accessed by JavaScript and readable by screen readers. This method is very useful for accessibility (
- ADA) development when more context is needed for visually-impaired users. As an alternative to display: none which is not readable by screen readers or visibility: hidden which takes up physical space in the
- DOM.
+
A bulletproof way to completely hide an element visually and positionally in the DOM while still allowing it to be accessed by JavaScript and readable by screen readers. This method is very useful for accessibility (ADA) development when more context is needed for visually-impaired users. As an alternative to display: none which is not readable by screen readers or visibility: hidden which takes up physical space in the DOM.
HTML
<a class="button" href="http://pantswebsite.com">
- Learn More
- <span class="offscreen"> about pants</span>
+ Learn More <span class="offscreen"> about pants</span>
</a>
Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.
HTML
<div class="overflow-scroll-gradient">
<div class="overflow-scroll-gradient__scroller">
- Lorem ipsum dolor sit amet consectetur adipisicing elit. <br>
- Iure id exercitationem nulla qui repellat laborum vitae, <br>
- molestias tempora velit natus. Quas, assumenda nisi. <br>
- Quisquam enim qui iure, consequatur velit sit? <br>
- Lorem ipsum dolor sit amet consectetur adipisicing elit.<br>
- Iure id exercitationem nulla qui repellat laborum vitae, <br>
- molestias tempora velit natus. Quas, assumenda nisi. <br>
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. <br />
+ Iure id exercitationem nulla qui repellat laborum vitae, <br />
+ molestias tempora velit natus. Quas, assumenda nisi. <br />
+ Quisquam enim qui iure, consequatur velit sit? <br />
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.<br />
+ Iure id exercitationem nulla qui repellat laborum vitae, <br />
+ molestias tempora velit natus. Quas, assumenda nisi. <br />
Quisquam enim qui iure, consequatur velit sit?
</div>
</div>
@@ -2250,47 +1881,45 @@ li:not(:last-child) {
- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit?
- Lorem ipsum dolor sit amet consectetur adipisicing elit.
- Iure id exercitationem nulla qui repellat laborum vitae,
- molestias tempora velit natus. Quas, assumenda nisi.
- Quisquam enim qui iure, consequatur velit sit?
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.
+ Iure id exercitationem nulla qui repellat laborum vitae,
+ molestias tempora velit natus. Quas, assumenda nisi.
+ Quisquam enim qui iure, consequatur velit sit?
+ Lorem ipsum dolor sit amet consectetur adipisicing elit.
+ Iure id exercitationem nulla qui repellat laborum vitae,
+ molestias tempora velit natus. Quas, assumenda nisi.
+ Quisquam enim qui iure, consequatur velit sit?
-
+
Explanation
position: relative on the parent establishes a Cartesian positioning context for pseudo-elements.
::after defines a pseudo element.
-
background-image: linear-gradient(...) adds a linear gradient that fades from transparent to white (top to bottom).
+
background-image: linear-gradient(...) adds a linear gradient that fades from transparent to white
+ (top to bottom).
position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
-
width: 240px matches the size of the scrolling element (which is a child of the parent that has the pseudo element).
+
width: 240px matches the size of the scrolling element (which is a child of the parent that has
+ the pseudo element).
height: 25px is the height of the fading gradient pseudo-element, which should be kept relatively small.
bottom: 0 positions the pseudo-element at the bottom of the parent.
pointer-events: none specifies that the pseudo-element cannot be a target of mouse events, allowing text behind it to still be selectable/interactive.
position: relative on the reference parent establishes a Cartesian positioning context for its child.
position: absolute takes the popout menu out of the flow of the document and positions it in relation to the parent.
left: 100% moves the the popout menu 100% of its parent's width from the left.
visibility: hidden hides the popout menu initially and allows for transitions (unlike display: none).
-
.reference:hover > .popout-menu means that when .reference is hovered over, select immediate children with a class of .popout-menu and change their visibility to visible,
- which shows the popout.
+
.reference:hover > .popout-menu means that when .reference is hovered over, select immediate children with a class of .popout-menu and change their visibility to visible, which shows the popout.
.reference:focus > .popout-menu means that when .reference is focused, the popout would be shown.
.reference:focus-within > .popout-menu ensures that the popout is shown when the focus is within the reference.
@@ -2391,8 +2007,8 @@ li:not(:last-child) {
Pretty text underlinevisual
-
A nicer alternative to text-decoration: underline or <u></u> where descenders do not clip the underline. Natively implemented as text-decoration-skip-ink: auto but it has less control over
- the underline.
+
A nicer alternative to text-decoration: underline or <u></u> where descenders do not clip the underline.
+ Natively implemented as text-decoration-skip-ink: auto but it has less control over the underline.
HTML
<p class="pretty-text-underline">Pretty text underline without clipping descending letters.</p>
Pretty text underline without clipping descending letters.
-
+
Explanation
-
text-shadow uses 4 values with offsets that cover a 4x4 px area to ensure the underline has a "thick" shadow that covers the line where descenders clip it. Use a color that matches the background. For a larger font, use a larger
- px size. Additional values can create an even thicker shadow, and subpixel values can also be used.
-
background-image: linear-gradient(...) creates a 90deg gradient using the text color (currentColor).
-
The background-* properties size the gradient as 100% of the width of the block and 1px in height at the bottom and disables repetition, which creates a 1px underline beneath the text.
-
The ::selection pseudo selector rule ensures the text shadow does not interfere with text selection.
-
+
text-shadow uses 4 values with offsets that cover a 4x4 px area to ensure the underline
+ has a "thick" shadow that covers the line where descenders clip it. Use a color
+ that matches the background. For a larger font, use a larger px size. Additional values
+ can create an even thicker shadow, and subpixel values can also be used.
+
background-image: linear-gradient(...) creates a 90deg gradient using the
+ text color (currentColor).
+
The background-* properties size the gradient as 100% of the width of the block and 1px
+ in height at the bottom and disables repetition, which creates a 1px underline beneath
+ the text.
+
The ::selection pseudo selector rule ensures the text shadow does not interfere with text
+ selection.
Resets all styles to default values with one property. This will not affect direction and unicode-bidi properties.
HTML
<div class="reset-all-styles">
<h5>Title</h5>
- <p>Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?</p>
+ <p>
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui
+ repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui
+ iure, consequatur velit sit?
+ </p>
</div>
Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui iure, consequatur velit sit?
+
+ Lorem ipsum dolor sit amet consectetur adipisicing elit. Iure id exercitationem nulla qui
+ repellat laborum vitae, molestias tempora velit natus. Quas, assumenda nisi. Quisquam enim qui
+ iure, consequatur velit sit?
+
-
+
Explanation
The all property allows you to reset all styles (inherited or not) to default values.
position: relative on the element establishes a Cartesian positioning context for pseudo elements.
::after defines a pseudo element.
-
background-image: url(...) adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can
- use
- the URL-encoder for SVG.
+
background-image: url(...) adds the SVG shape (a 24x12 triangle) as the background image of the pseudo element, which repeats by default. It must be the same color as the block that is being separated. For other shapes, we can use the URL-encoder for SVG.
position: absolute takes the pseudo element out of the flow of the document and positions it in relation to the parent.
width: 100% ensures the element stretches the entire width of its parent.
transition: opacity 0.2s specifies that changes to opacity will be transitioned over 0.2 seconds.
-
.sibling-fade:hover span:not(:hover) specifies that when the parent is hovered, select any span children that are not currently being hovered and change their opacity to 0.5.
+
.sibling-fade:hover span:not(:hover) specifies that when the parent is hovered, select any span children
+ that are not currently being hovered and change their opacity to 0.5.
The browser looks for each successive font, preferring the first one if possible, and falls back to the next if it cannot find the font (on the system or defined in CSS).
+
The browser looks for each successive font, preferring the first one if possible, and
+ falls back to the next if it cannot find the font (on the system or defined in CSS).
-apple-system is San Francisco, used on iOS and macOS (not Chrome however)
BlinkMacSystemFont is San Francisco, used on macOS Chrome
This effect is styling only the <label> element to look like a toggle switch, and hiding the actual <input> checkbox by positioning it offscreen. When clicking the label associated with the <input> element, it sets the <input> checkbox into the :checked state.
+
This effect is styling only the <label> element to look like a toggle switch, and hiding the actual <input> checkbox by positioning it offscreen. When clicking the label associated with the <input> element, it sets the <input> checkbox into the :checked state.
The for attribute associates the <label> with the appropriate <input> checkbox element by its id.
.switch::after defines a pseudo-element for the <label> to create the circular knob.
input[type='checkbox']:checked + .switch::after targets the <label>'s pseudo-element's style when the checkbox is checked.
transform: translateX(20px) moves the pseudo-element (knob) 20px to the right when the checkbox is checked.
background-color: #7983ff; sets the background-color of the switch to a different color when the checkbox is checked.
-
.offscreen moves the <input> checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it
- is accessible via keyboard and screen readers.
-
transition: all 0.3s specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the <label>'s background-color and the pseudo-element's transform property when the checkbox is checked.
+
.offscreen moves the <input> checkbox element, which does not comprise any part of the actual toggle switch, out of the flow of document and positions it far away from the view, but does not hide it so it is accessible via keyboard and screen readers.
+
transition: all 0.3s specifies all property changes will be transitioned over 0.3 seconds, therefore transitioning the <label>'s background-color and the pseudo-element's transform property when the checkbox is checked.
Vertically and horizontally centers a child element within its parent element using position: absolute and transform: translate() (as an alternative to flexbox or display: table). Similar
- to flexbox, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.
Vertically and horizontally centers a child element within its parent element using position: absolute and transform: translate() (as an alternative to flexbox or display: table). Similar to flexbox, this method does not require you to know the height or width of your parent or child so it is ideal for responsive applications.
The color of the border is the color of the triangle. The side the triangle tip points corresponds to the opposite border-* property. For example, a color on border-top means the arrow points downward.
The color of the border is the color of the triangle. The side the triangle tip points
+ corresponds to the opposite border-* property. For example, a color on border-top
+ means the arrow points downward.
Experiment with the px values to change the proportion of the triangle.
Use the :nth-child(odd) or :nth-child(even) pseudo-class to apply a different background color to elements that match based on their position in a group of siblings.
+
+
Note that you can use it to apply different styles to other HTML elements like div, tr, p, ol, etc.