
Tailwind CSS code examples
Browse 264 Tailwind CSS code examples across 22 topics, including box model and sizing, flexbox, grid.
Jump to a topic
Box model and sizing
- Border-box sizing
- Content-box sizing
- Minimum inline size
- Maximum reading width
- Width that follows content
- Fluid width with a maximum
- Minimum block height
- Square aspect ratio
- Widescreen aspect ratio
- Asymmetric padding
- Logical start padding
- Centre a fixed-width box with margins
- Negative margin overlap
- Resize a text area vertically
Flexbox
- Horizontal flex row
- Vertical flex stack
- Reverse a flex row
- Reverse a flex column
- Wrap a flex row onto new lines
- Reverse the wrap direction
- Put space between flex items
- Put equal space around flex items
- Align items at the cross-axis end
- Align text on its baseline
- Let one flex item absorb free space
- Give flex items equal initial sizes
- Change one item's cross-axis alignment
- Prevent a flex item from shrinking
Grid
- Create three equal columns
- Mix fixed and flexible columns
- Build responsive auto-fit tracks
- Reserve empty columns with auto-fill
- Span two columns with one item
- Place an item in a specific column
- Span two grid rows
- Set a minimum for implicit rows
- Fill grid columns before rows
- Centre grid items on both axes
- Move the grid tracks to the corner
- Use different row and column gaps
- Name grid areas for a simple layout
- Use a subgrid for shared columns
Typography
- Use a system monospace family
- Use a system serif family
- Style a prominent heading
- Set a comfortable line height
- Increase tracking on a label
- Use tabular figures for aligned totals
- Use old-style numerals
- Balance a multiline headline
- Keep text on one line
- Allow wrapped justification at the start edge
- Offset an underline
- Give a decoration its own colour
- Indent the first line
- Keep a super-script from changing line height
Position and stacking
- Place a badge in a corner
- Pin a layer to all four edges
- Use logical positioning in RTL
- Centre an absolutely positioned layer
- Keep a subheading visible while scrolling
- Pin a label to the preview viewport
- Put an earlier item on top
- Create an isolated stacking context
- Offset a relatively positioned item
- Layer two items with grid
- Float a label alongside copy
- Clear both floats before the next paragraph
- Contain a float with flow-root
- Remove an item from normal flow with absolute
Responsive layout
- Stack small screens and align large ones
- Increase grid columns at a breakpoint
- Show a compact label below a breakpoint
- Use a breakpoint range
- Scale text fluidly with clamp
- Apply fluid spacing with a ceiling
- Set page width with a viewport gutter
- Switch presentation in portrait view
- Offer stronger contrast when requested
- Style a printable note
- Size content from viewport height
- Respond to the width of a container
- Scale a label with its container width
- Use three viewport sizes for gutters
Colour and backgrounds
- Set a solid surface colour
- Tint only the background
- Apply transparency to the whole element
- Set a linear gradient
- Use a middle gradient stop
- Draw a radial gradient
- Draw a conic gradient
- Create repeating diagonal stripes
- Clip a gradient to large text
- Choose colours from the system theme
- Mix two colours in a perceptual space
- Use one custom property for coordinated colour
- Blend two overlapping shapes
- Show a background only inside padding
Borders and effects
- Round every corner
- Round only the top corners
- Make a pill-shaped label
- Use a dashed border
- Accent a logical start border
- Create a double border
- Draw an outline outside the border
- Apply an inset box shadow
- Stack two box shadows
- Build a ring without changing layout
- Separate consecutive rows with borders
- Limit a drop shadow to the shape
- Build a frosted translucent panel
- Convert a treatment to grayscale
Overflow and scrolling
- Truncate a single line with an ellipsis
- Clamp a paragraph to two lines
- Break an unbroken token anywhere
- Break words at any character
- Preserve newlines and wrap long lines
- Clip content without a scroll container
- Allow horizontal scrolling only
- Reserve room for a scrollbar
- Stop scroll chaining at a panel edge
- Snap a horizontal card rail
- Target an anchor with breathing room
- Give scroll targets an extra margin
- Let the browser hyphenate long words
- Allow a description to expand without clipping
Interaction states
- Change a button background on hover
- Give keyboard focus a clear outline
- Give an active button press feedback
- Dim a disabled control
- Highlight a field group on focus
- Show a pressed ARIA toggle style
- Style a selected item with a data attribute
- Change a child when hovering its parent
- Change a label when its input is checked
- Style a container with a checked child
- Highlight text selection
- Change cursor on a resizable handle
- Prevent pointer events on a decorative layer
- Show which details panel is open
Forms and controls
- Colour the native checkbox accent
- Style placeholder text
- Make a text cursor easier to see
- Highlight a required field
- Highlight invalid input after editing
- Show a read-only field with a softer colour
- Style the file picker button
- Let a textarea grow as you type
- Use a custom-sized native range control
- Mark a field that is outside numeric bounds
- Emphasize a control that has a hint
- Keep native rendering in forced colours
- Show dependent fields when a choice is selected
- Style focus independently of keyboard modality
Transforms and motion
- Rotate a swatch
- Scale a shape on hover
- Translate along the X axis
- Skew a label
- Change the origin of rotation
- Rotate a card in perspective
- Hide the back face of a card
- Transition only text and background colours
- Use a delayed transition
- Ease a transition with a custom curve
- Animate a loading indicator
- Pulse a decorative status marker
- Disable a transition for reduced motion
- Flip artwork horizontally
Selectors and generated content
- Alternate background colours in a list
- Style the first child only
- Remove the last row divider
- Style exactly one child
- Show a placeholder for an empty panel
- Add a purely decorative leading mark
- Draw a decorative trailing line
- Change the first letter of a paragraph
- Emphasize the first rendered line
- Colour list markers separately from their text
- Emphasize the current navigation item
- Style a deep descendant without styling siblings
- Give standalone buttons extra padding
- Keep grouped selectors at low specificity
Media and shapes
- Crop an image to fill a square
- Fit the entire image inside a square
- Align an image crop to the left edge
- Place an image above adjacent inline text
- Fade the edges of a photo
- Increase image saturation
- Warm an image with sepia
- Reduce image contrast
- Clip an image into a circular avatar
- Clip a swatch to a diamond
- Set an SVG fill from the text colour
- Set an SVG stroke from the text colour
- Expose colour channels with an invert filter
- Rotate image hues
Document flow and lists
- Flow text into two columns
- Automatically fit narrow text columns
- Add a divider between text columns
- Keep each card together in multicolumn flow
- Force a new text column before a heading
- Span a headline across text columns
- Place list markers within the text flow
- Use lower Roman numerals for a list
- Number a sequence with CSS counters
- Align numeric table cells to the end
- Share a border between table cells
- Space separate table borders
- Let columns size from the declared table width
- Keep a caption below its table
Accessibility and international layouts
- Visually hide an accessible label
- Reveal a skip link on keyboard focus
- Keep an invisible spacer in the layout
- Remove a spacer from the layout entirely
- Keep status information visible without colour
- Increase a button hit area with padding
- Expose bidi-safe user content
- Stack vertical writing lines right to left
- Keep glyphs upright in vertical writing
- Use two-line spacing with logical margins
- Mirror a directional icon in right-to-left content
- Always allow selection of a reference code
- Allow an inner panel to scroll even with keyboard focus
- Make the thicker text visible on dark and light backgrounds