CSS
Modern CSS techniques for better layouts, responsive interfaces, cleaner stylesheets, and solving everyday front-end development challenges.
Browse 97 articles in this topic. View all topics.
- CSS Calculations With sibling-index() and sibling-count()
Use CSS sibling-index() and sibling-count() for staggered animations and position-based calculations, with working examples and browser support checks.
- Using HTML Attribute Values Inside CSS With attr()
CSS attr() reads HTML attributes for generated labels and typed calculations. Use working examples, check support, and handle missing or invalid values.
- Round CSS sizes to fixed steps with round()
CSS round() snaps responsive values to useful steps. See rounding strategies, spacing scales, and a column calculation, with browser support checks.
- What the Browser Already Does Without a Framework
Before adding a frontend framework, check what HTML, CSS, forms, responsive images, preferences, and browser navigation already provide.
- Better Line Breaks With CSS balance and pretty
Use text-wrap balance for short headings and text-wrap pretty selectively for longer copy without hard-coded line breaks.
- Why 100vh Doesn’t Always Fit a Mobile Screen
Why 100vh can exceed the visible mobile screen. Choose svh, lvh, or dvh, let content grow, and put older Safari workarounds in their historical context.
- Making Links Easy to Recognize
Make links recognisable with underlines, clear focus states, useful text, and behaviour that does not surprise the reader.
- When CSS Layout Order Stops Matching the HTML
Keep Grid and Flexbox layouts aligned with the HTML order so keyboard focus and screen reader reading do not jump around the page.
- Keyboard Focus Styles With :focus-visible
Keep a clear keyboard focus indicator while avoiding the same focus ring after every pointer interaction.
- Where CSS Performance Problems Come From
Focus CSS performance work on stylesheet weight, layout, painting, DOM size, and unused rules before benchmarking ordinary selectors.
- When CSS @supports Is Useful
Add modern CSS with @supports feature queries when unsupported browsers need a genuinely different layout or behaviour.
- Show Form Errors After Interaction With :user-invalid
Use :user-invalid and :user-valid to style native HTML validation states without marking untouched fields as errors.
- Smoother Page Changes With View Transitions
Use the View Transition API for same-page state changes and progressive cross-document animation on a normal multi-page site.
- Styling Scrollbars With Modern CSS
Style scrollbar width and colours with standard CSS, while keeping the control visible, usable, and familiar.
- When to use CSS clip-path or mask
Choose between CSS clip-path and mask by deciding whether the element needs a hard boundary or levels of transparency.
- Fading images with CSS masks
Use CSS masks for image fades, scroll hints, cutouts, and recolourable icons without changing the source asset.
- Responsive shapes with CSS shape()
Use the CSS shape() function for scalable clipping paths with lines and curves, while keeping a simple fallback.
- CSS @property Gives Variables a Type
Register a CSS custom property with a type, initial value, and inheritance rule so the browser can validate and animate it.
- Modern CSS You Can Actually Use Today
A practical selection of modern CSS features that simplify real websites, with a focused example for each one.
- Expandable sections with HTML details and summary
Build simple accordions and disclosure sections with the native HTML details and summary elements.