Close Menu

    Subscribe to Updates

    Get the latest creative news from FooBar about art, design and business.

    What's Hot

    How to make Happy birthday cake Animation using HTML & CSS

    29 May 2025

    How to create Toast Catcher Game using HTML CSS and JS

    26 May 2025

    How to create Animated No Chill Login form using HTML CSS and JS

    22 May 2025
    Facebook X (Twitter) Instagram YouTube Telegram Threads
    Coding StellaCoding Stella
    • Home
    • Blog
    • HTML & CSS
      • Login Form
    • JavaScript
    • Hire us!
    Coding StellaCoding Stella
    Home - Blog - 20 CSS Tricks You Probably Didn’t Know About
    Blog

    20 CSS Tricks You Probably Didn’t Know About

    Coding StellaBy Coding Stella25 January 2024Updated:25 January 20242 Comments4 Mins Read
    Share Facebook Twitter Pinterest LinkedIn Tumblr Reddit Email WhatsApp Copy Link

    Explore hidden gems in web design with ’20 CSS Tricks You Probably Didn’t Know About.’ Uncover innovative and lesser-known CSS techniques to enhance your website’s style and functionality.

    Ever wondered if there are more cool things you can do with CSS? Join me for a quick look at 20 CSS hidden tricks that could be your secret weapons for making awesome websites. Get ready to learn some new CSS tricks!

    1. Smooth Scroll Magic

    Make scrolling smooth by adding scroll-behavior: smooth to your HTML. This CSS property smoothens the scrolling behavior for the entire page.

    html {
        scroll-behavior: smooth;
    }

    2. Link Charmers

    Give a distinctive look to links starting with “https” by changing their color to red. This is achieved using an attribute selector.

    a[href^="https"] {
        color: red;
    }

    3. Sibling Symphony

    Apply styles to paragraphs that come after an h1 element. The ~ selector targets siblings that follow a specified element.

    h1 ~ p {
        color: yellow;
    }

    4. The Rebel :not()

    Style list items that don’t have the class “special” with italic font.

    li:not(.special) {
        font-style: italic;
    }

    5. Responsive Typography with Viewport Units

    Make font sizes responsive to the viewport size by using viewport units (vw). In this example, the font size of h1 is set to 15% of the viewport width.

    h1 {
        font-size: 15vw;
    }

    6. :empty Elegance

    Hide empty paragraphs using the :empty pseudo-class. This ensures that paragraphs without content are not displayed.

    p:empty {
        display: none;
    }

    7. Variable Visions

    Define custom properties (variables) at the root level for easier theming and maintenance. In this case, a main color variable is set and used in styling an h2 element.

    :root {
        --main-color: #349832;
    }
    
    h2 {
        color: var(--main-color);
    }

    8. Image Wizardry with Object-fit

    Control how images should be resized within their frames using the object-fit property. In this example, the cover value is used to ensure the entire image is visible while maintaining its aspect ratio.

    img {
        width: 100px;
        height: 100px;
        object-fit: cover;
    }

    9. Grid Glory

    Utilize the power of CSS Grid for simplified and flexible layouts. In this example, a container is set to display as a grid with three columns of equal width.

    .container {
        display: grid;
        grid-template-columns: 1fr 2fr 1fr;
    }

    10. :focus-within pseudo class

    Apply styles to a form when it contains focused elements. The :focus-within pseudo-class selects an element if any of its children have focus.

    form:focus-within {
        box-shadow: 0 0 15px rgba(0, 0, 0, 0.3);
    }

    11. Vertical centering with flexbox

    Easily center content both horizontally and vertically within a container using flexbox.

    .container {
       display: flex;
       align-items: center;
       justify-content: center;
    }

    12. Custom highlight color for selections

    Customize the highlight color when text is selected on your webpage.

    ::selection {
       background-color: #ffcc00;
       color: #333;
    }

    13. Styling placeholder text

    Style the placeholder text inside input fields.

    ::placeholder {
       color: #999;
       font-style: italic;
    }

    14. Gradient borders

    Create gradient borders using the background-clip property.

    .element {
       border: 2px solid transparent;
       background-clip: padding-box;
       background-image: linear-gradient(to right, red, blue);
    }

    15. Variable font sizes with vw

    Adjust font size based on the viewport width, allowing for more responsive typography.

    body {
       font-size: calc(16px + 1vw);
    }

    16. Conic gradients for colorful elements

    Create colorful and dynamic backgrounds using conic gradients.

    .element {
       background: conic-gradient(#ff5733, #33ff57, #5733ff);
    }

    17. Clamp() function for responsive text

    Use the clamp() function to set a range for font size, ensuring readability on different screen sizes.

    .text {
       font-size: clamp(16px, 4vw, 24px);
    }

    18. Efficient font loading with font display swap

    Use the font-display: swap; property to improve the performance of web fonts by displaying fallback fonts while the custom font is loading.

    @font-face {
       font-family: 'YourFont';
       src: url('your-font.woff2') format('woff2');
       font-display: swap;
    }

    19. Custom scroll snap points

    Implement custom scroll snap points for a smoother scrolling experience, especially useful for image galleries or sliders.

    .scroll-container {
       scroll-snap-type: y mandatory;
    }
    
    .scroll-item {
       scroll-snap-align: start;
    }

    20. Variable font styling with font variation settings

    Utilize variable fonts and the font-variation-settings property for fine-tuned control over font weight, style, and other variations.

    .text {
       font-family: 'YourVariableFont', sans-serif;
       font-variation-settings: 'wght' 500, 'ital' 1;
    }

    Conclusion

    These advanced CSS techniques provide a range of options for creating more interactive, dynamic, and responsive web designs. Experimenting with these features can enhance the visual appeal and functionality of your web projects.

    Coding Efficiency Coding Tips CSS Hacks CSS Secrets CSS Shortcuts CSS Skills CSS Techniques CSS Tips CSS Tricks Front-End Development Front-End Tips Web Design Web Development Web Development Tricks
    Share. Copy Link Twitter Facebook LinkedIn Email WhatsApp
    Previous ArticleBest Programming Languages for Web Development
    Next Article 10 Must-Have VSCode Extensions for Web Development 🛸
    Coding Stella
    • Website

    Related Posts

    HTML & CSS

    How to make Awesome Search Bar 2 using HTML & CSS

    4 April 2025
    Blog

    50 Projects in 50 Days – HTML/CSS and JavaScript

    23 February 2025
    Blog

    Frontend Developer Roadmap 2025: The Complete Guide

    31 January 2025
    View 2 Comments

    2 Comments

    1. Pingback: Top 10 Most Popular Programming Languages of All Time | Coding Stella

    2. Pingback: Learn CSS By Playing Games | Coding Stella

    Leave A Reply Cancel Reply

    Trending Post

    Master Frontend in 100 Days Ebook

    2 March 202419K Views

    How to make Modern Login Form using HTML & CSS | Glassmorphism

    11 January 202416K Views

    How to make I love you Animation in HTML CSS & JavaScript

    14 February 202414K Views

    How to make Valentine’s Day Card using HTML & CSS

    13 February 202412K Views
    Follow Us
    • Instagram
    • Facebook
    • YouTube
    • Twitter
    ads
    Featured Post

    HTML Cheat Sheet | Mastering HTML : Your Go-To Cheat Sheet

    31 January 2024

    52 Frontend Interview Questions – Ft. JavaScript

    26 January 2024

    How to make Animated Download Button using HTML CSS & JavaScript

    28 November 2024

    How to create Valentine’s Day Letter using HTML CSS & JavaScript

    14 February 2025
    Latest Post

    How to make Happy birthday cake Animation using HTML & CSS

    29 May 2025

    How to create Toast Catcher Game using HTML CSS and JS

    26 May 2025

    How to create Animated No Chill Login form using HTML CSS and JS

    22 May 2025

    How to make Social media icons hover effect using HTML & CSS

    14 May 2025
    Facebook X (Twitter) Instagram YouTube
    • About Us
    • Privacy Policy
    • Return and Refund Policy
    • Terms and Conditions
    • Contact Us
    • Buy me a coffee
    © 2025 Coding Stella. Made with 💙 by @coding.stella

    Type above and press Enter to search. Press Esc to cancel.

    Ad Blocker Enabled!
    Ad Blocker Enabled!
    Looks like you're using an ad blocker. We rely on advertising to help fund our site.
    Okay! I understood