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

      A Week In The Life Of An AI-Augmented Designer

      August 22, 2025

      This week in AI updates: Gemini Code Assist Agent Mode, GitHub’s Agents panel, and more (August 22, 2025)

      August 22, 2025

      Microsoft adds Copilot-powered debugging features for .NET in Visual Studio

      August 21, 2025

      Blackstone portfolio company R Systems Acquires Novigo Solutions, Strengthening its Product Engineering and Full-Stack Agentic-AI Capabilities

      August 21, 2025

      The best AirTag alternative for Samsung users is currently 30% off

      August 24, 2025

      One of the biggest new features on the Google Pixel 10 is also one of the most overlooked

      August 24, 2025

      I tested these viral ‘crush-proof’ Bluetooth speakers, and they’re not your average portables

      August 24, 2025

      I compared the best smartwatches from Google and Apple – and there’s a clear winner

      August 24, 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

      MongoDB Data Types

      August 23, 2025
      Recent

      MongoDB Data Types

      August 23, 2025

      Building Cross-Platform Alerts with Laravel’s Notification Framework

      August 23, 2025

      Add Notes Functionality to Eloquent Models With the Notable Package

      August 23, 2025
    • Operating Systems
      1. Windows
      2. Linux
      3. macOS
      Featured

      Microsoft Teams updated with a feature you probably thought already existed — “Can you hear me?” is now a thing of the past

      August 24, 2025
      Recent

      Microsoft Teams updated with a feature you probably thought already existed — “Can you hear me?” is now a thing of the past

      August 24, 2025

      Xbox Game Pass gets Gears of War: Reloaded, Dragon Age: The Veilguard, and more — here’s what is coming through the rest of August

      August 24, 2025

      Resident Evil ‘9’ Requiem has some of the most incredible lighting I’ve seen in a game — and Capcom uses it as a weapon

      August 24, 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

    The best AirTag alternative for Samsung users is currently 30% off

    August 24, 2025
    News & Updates

    One of the biggest new features on the Google Pixel 10 is also one of the most overlooked

    August 24, 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

    CVE-2025-7504 – WordPress Friends Plugin PHP Object Injection Vulnerability

    Common Vulnerabilities and Exposures (CVEs)

    Query Amazon Aurora PostgreSQL using Amazon Bedrock Knowledge Bases structured data

    Machine Learning

    What Makes a Stock Graphic Truly ‘Premium’?

    Web Development

    Java at 30: How a language designed for a failed gadget became a global powerhouse

    News & Updates

    Highlights

    A Coding Guide for Building a Self-Improving AI Agent Using Google’s Gemini API with Intelligent Adaptation Features

    May 29, 2025

    In this tutorial, we will explore how to create a sophisticated Self-Improving AI Agent using…

    Proposte e Polemiche: XLibre non entrerà nei pacchetti ufficiali di NixOS

    July 15, 2025

    CVE-2025-30084 – Joomla RSMail! Stored XSS

    June 5, 2025

    CVE-2025-44884 – D-Link FW-WGS-804HPT Stack Overflow Vulnerability

    May 20, 2025
    © DevStackTips 2025. All rights reserved.
    • Contact
    • Privacy Policy

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