CSS Snippets

CSS

Height transition
CSS, Animation, Intermediate

Transitions an element's height from 0 to auto when its height is unknown.

Bouncing loader
CSS, Animation, Intermediate

Creates a bouncing loader animation.

Hover underline animation
CSS, Animation, Intermediate

Creates an animated underline effect when the text is hovered over.

Button border animation
CSS, Animation, Intermediate

Creates a border animation on hover.

Staggered animation
CSS, Animation, Intermediate

Creates a staggered animation for the elements of a list.

Hover shadow box animation
CSS, Animation, Intermediate

Creates a shadow box around the text when it is hovered.

Easing variables
CSS, Animation, Intermediate

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.

Pulse loader
CSS, Animation, Intermediate

Creates a pulse effect loader animation using the animation-delay property.

Image rotate on hover
CSS, Animation, Intermediate

Creates a rotate effect for the image on hover.

Donut spinner
CSS, Animation, Intermediate

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

Hamburger Button
CSS, Interactivity, Beginner

Displays a hamburger menu which transitions to a cross on hover.

Popout menu
CSS, Interactivity, Beginner

Reveals an interactive popout menu on hover and focus.

Sibling fade
CSS, Interactivity, Beginner

Fades out the siblings of a hovered item.

Disable selection
CSS, Interactivity, Beginner

Makes the content unselectable.

Menu on image hover
CSS, Layout, Intermediate

Displays a menu overlay when the image is hovered.

Offscreen
CSS, Layout, Intermediate

Completely hides an element visually and positionally in the DOM while still allowing it to be accessible. Provides an alternative to display: none (not readable by screen readers) and visibility: hidden (takes up physical space in the DOM).

Truncate text multiline
CSS, Layout, Intermediate

If the text is longer than one line, it will be truncated for n lines and end with an gradient fade.

3-tile layout
CSS, Layout, Intermediate

Align items horizontally using display: inline-block to create a 3-tile layout.

Masonry Layout
CSS, Layout, Intermediate

Creates a vertical masonry layout using HTML and CSS.

Fit image in container
CSS, Layout, Intermediate

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.

Clearfix
CSS, Layout, Intermediate

Ensures that an element self-clears its children.

Display table centering
CSS, Layout, Intermediate

Vertically and horizontally centers a child element within its parent element using display: table (as an alternative to flexbox).

Learn how CSS custom properties (CSS variables) work and what you can use them for in your code and designs.

Transform centering
CSS, Layout, Beginner

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.

Flexbox allows you to create fluid layouts easily. If you find yourself constantly looking up the syntax or how it work, this handy cheatsheet is all you need.

Truncate text
CSS, Layout, Beginner

If the text is longer than one line, it will be truncated and end with an ellipsis ….

Box-sizing reset
CSS, Layout, Beginner

Resets the box-model so that width and height are not affected by border or padding.

Evenly distributed children
CSS, Layout, Intermediate

Evenly distributes child elements within a parent element.

Constant width to height ratio
CSS, Layout, Beginner

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).

Flexbox centering
CSS, Layout, Beginner

Horizontally and vertically centers a child element within a parent element using flexbox.

Grid centering
CSS, Layout, Beginner

Horizontally and vertically centers a child element within a parent element using Grid.

Fancy hover and focus effect at navigation items using transform CSS property.

Mouse cursor gradient tracking
CSS, Visual, Advanced

A hover effect where the gradient follows the mouse cursor.

Toggle switch
CSS, Visual, Beginner

Creates a toggle switch with CSS only.

Image overlay on hover
CSS, Visual, Advanced

Displays an image overlay effect on hover.

Fullscreen
CSS, Visual, Advanced

The :fullscreen CSS pseudo-element represents an element that's displayed when the browser is in fullscreen mode.

Focus Within
CSS, Visual, Intermediate

Changes the appearance of a form if any of its children are focused.

Counter
CSS, Visual, Advanced

Counters are, in essence, variables maintained by CSS whose values may be incremented by CSS rules to track how many times they're used.

Overflow scroll gradient
CSS, Visual, Intermediate

Adds a fading gradient to an overflowing element to better indicate there is more content to be scrolled.

Custom scrollbar
CSS, Visual, Advanced

Customizes the scrollbar style for the document and elements with scrollable overflow, on WebKit platforms.

Zebra striped list
CSS, Layout, Beginner

Creates a striped list with alternating background colors, which is useful for differentiating siblings that have content spread across a wide row.

Border with top triangle
CSS, Layout, Beginner

Creates a text container with a triangle at the top.

Dynamic shadow
CSS, Visual, Intermediate

Creates a shadow similar to box-shadow but based on the colors of the element itself.

Ⓒ Repository by Code Honchos