Close Menu
    DevStackTipsDevStackTips
    • Home
    • News & Updates
      1. Tech & Work
      2. View All

      15 Proven Benefits of Outsourcing Node.js Development for Large Organizations

      July 9, 2025

      10 Reasons to Choose Full-Stack Techies for Your Next React.js Development Project

      July 9, 2025

      Anthropic proposes transparency framework for frontier AI development

      July 8, 2025

      Sonatype Open Source Malware Index, Gemini API Batch Mode, and more – Daily News Digest

      July 8, 2025

      Microsoft sees its carbon emissions soar on a 168% glut in AI energy demand, “we recognize that we must also bring more carbon-free electricity onto the grids.”

      July 9, 2025

      You can get a Snapdragon X-powered laptop for under $500 right now — a low I didn’t think we’d see this Prime Day week

      July 9, 2025

      Sam Altman admits current computers were designed for an AI-free world — but OpenAI’s new type of computer will make the AI revolution “transcendentally good”

      July 9, 2025

      It doesn’t matter how many laptops I review or how great the deals are — this is the one I keep coming back to over and over again

      July 9, 2025
    • Development
      1. Algorithms & Data Structures
      2. Artificial Intelligence
      3. Back-End Development
      4. Databases
      5. Front-End Development
      6. Libraries & Frameworks
      7. Machine Learning
      8. Security
      9. Software Engineering
      10. Tools & IDEs
      11. Web Design
      12. Web Development
      13. Web Security
      14. Programming Languages
        • PHP
        • JavaScript
      Featured

      Leading Experts in Meme Coin Development – Beleaf Technologies

      July 9, 2025
      Recent

      Leading Experts in Meme Coin Development – Beleaf Technologies

      July 9, 2025

      Redefining Quality Engineering – Tricentis India Partner Event

      July 9, 2025

      Enhancing JSON Responses with Laravel Model Appends

      July 9, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft sees its carbon emissions soar on a 168% glut in AI energy demand, “we recognize that we must also bring more carbon-free electricity onto the grids.”

      July 9, 2025
      Recent

      Microsoft sees its carbon emissions soar on a 168% glut in AI energy demand, “we recognize that we must also bring more carbon-free electricity onto the grids.”

      July 9, 2025

      You can get a Snapdragon X-powered laptop for under $500 right now — a low I didn’t think we’d see this Prime Day week

      July 9, 2025

      Sam Altman admits current computers were designed for an AI-free world — but OpenAI’s new type of computer will make the AI revolution “transcendentally good”

      July 9, 2025
    • Learning Resources
      • Books
      • Cheatsheets
      • Tutorials & Guides
    Home»News & Updates»You can style alt text like any other text

    You can style alt text like any other text

    May 22, 2025

    Clever, clever that Andy Bell. He shares a technique for displaying image alt text when the image fails to load. Well, more precisely, it’s a technique to apply styles to the alt when the image doesn’t load, offering a nice UI fallback for what would otherwise be a busted-looking error.

    The recipe? First, make sure you’re using alt in the HTML. Then, a little JavaScript snippet that detects when an image fails to load:

    const images = document.querySelectorAll("img");
    
    if (images) {
      images.forEach((image) => {
        image.onerror = () => {
          image.setAttribute("data-img-loading-error", "");
        };
      });
    }

    That slaps an attribute on the image — data-img-loading-error — that is selected in CSS:

    img[data-img-loading-error] {
      --img-border-style: 0.25em solid
        color-mix(in srgb, currentColor, transparent 75%);
      --img-border-space: 1em;
    
      border-inline-start: var(--img-border-style);
      border-block-end: var(--img-border-style);
      padding-inline-start: var(--img-border-space);
      padding-block: var(--img-border-space);
      max-width: 42ch;
      margin-inline: auto;
    }

    And what you get is a lovely little presentation of the alt that looks a bit like a blockquote and is is only displayed when needed.

    CodePen Embed Fallback

    Andy does note, however, that Safari does not render alt text if it goes beyond a single line, which 🤷‍♂️.


    You can style alt text like any other text originally published on CSS-Tricks, which is part of the DigitalOcean family. You should get the newsletter.

    Source: Read More 

    Facebook Twitter Reddit Email Copy Link
    Previous ArticleGNOME Dropping X11 Support May Complicate Next Ubuntu LTS
    Next Article Ubuntu 25.10 Will Ship with the Linux 6.17 Kernel

    Related Posts

    News & Updates

    Microsoft sees its carbon emissions soar on a 168% glut in AI energy demand, “we recognize that we must also bring more carbon-free electricity onto the grids.”

    July 9, 2025
    News & Updates

    You can get a Snapdragon X-powered laptop for under $500 right now — a low I didn’t think we’d see this Prime Day week

    July 9, 2025
    Leave A Reply Cancel Reply

    For security, use of Google's reCAPTCHA service is required which is subject to the Google Privacy Policy and Terms of Use.

    Continue Reading

    GOG just saved one of the greatest JRPGs of all time — availablenowonPC

    News & Updates

    Microsoft Releases a Comprehensive Guide to Failure Modes in Agentic AI Systems

    Machine Learning

    CVE-2025-49257 – ThemBay Zota PHP Remote File Inclusion Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    How iPadOS 26 convinced me to switch from Mac to iPad full-time – and why I don’t regret it

    News & Updates

    Highlights

    Typhoon-like gang slinging TLS certificate ‘signed’ by the Los Angeles Police Department

    June 23, 2025

    Typhoon-like gang slinging TLS certificate ‘signed’ by the Los Angeles Police Department

    A stealthy, ongoing campaign to gain long-term access to networks bears all the markings of intrusions conducted by China’s ‘Typhoon’ crews and has infected at least 1,000 devices, primarily in the US …
    Read more

    Published Date:
    Jun 23, 2025 (3 hours, 7 minutes ago)

    Vulnerabilities has been mentioned in this article.

    CVE-2017-17663

    CVE-2015-1548

    I’m an off-grid expert, and this 2600W power station on sale for $800 off won’t last long

    June 24, 2025

    How to Download Microsoft Office on Windows 11 (Beginner-Friendly Guide)

    July 2, 2025

    CVE-2025-37094 – HPE StoreOnce Directory Traversal File Deletion Vulnerability

    June 2, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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