Tagged: html

  • Note - Posted on

    Today I learned, via Calibre’s article on Lazy Loading Images, there is a difference in how far ahead each browser fetches lazy images.

    BrowserImagesIframesVideo and audio
    Chrome, 4G1,250px2,500px1,250px
    Chrome, 3G2,500px3,500px2,500px
    Chrome, 2G6,000px6,000px6,000px
    Firefox600px600pxNot supported
    SafariOne viewport0pxNot supported

    Additionally, there is a difference in how horizontal lazy loading works in Chrome, Safari and Firefox. Via web.dev’s article on Browser-level image lazy loading for the web:

    Chrome 121 changed the behavior for horizontal-scrolling images like carousels. These now use the same thresholds as vertical scrolling. This means for the carousel use case, images will be loaded before they visible in the viewport. This means the image loading is less likely to be noticeable to the user, but at the cost of more downloads. Use the Horizontal Lazy Loading demo to compare behaviour in Chrome versus Safari and Firefox.

  • Note - Posted on

    Today I learned, lazy loading only works when JavaScript is enabled.

    As per the HTML spec,

    This is an anti-tracking measure, because if a user agent supported lazy loading when scripting is disabled, it would still be possible for a site to track a user’s approximate scroll position throughout a session, by strategically placing images in a page’s markup such that a server can track how many images are requested and when.

  • Note - Posted on

    Today I learned, elements with a positive tabindex value are focused first, from the lowest value up, before tabindex=“0” in sequential keyboard navigation.

    I was completely unaware of this behaviour. I guess because I had only ever used tabindex=“0” (for scrollable overflow containers) and tabindex=“-1” (to remove an element from sequential keyboard navigation) until now.

    Also, via MDN’s reference page on tabindex HTML global attribute:

    Some focusable HTML elements have a default tabindex value of 0 set under the hood by the user agent. These elements are an <a> or <area> with href attribute, <button>, <frame> , <iframe>, <input>, <object>, <select>, <textarea>, and SVG <a> element, or a <summary> element that provides summary for a <details> element.

  • Note - Posted on

    tabindex="-1" (or any negative value) makes an element focusable if it isn’t already, and removes it from the tab order. It can still receive focus programmatically or by click, but not via the Tab key.

  • Note - Posted on

    Today I learned that modal <dialog>s opened with showModal() can have their own <h1>.

    I discovered this while reading Modern Web Guidance’s HTML guide. I was skeptical at first because it’s bad practice to have multiple <h1>s on a single web page.

    But this exception for modal dialogs made sense when I learned what showModal() does. It makes the rest of the page inert and as mentioned on MDN, inert HTML elements and their flat tree descendants are hidden from assistive technologies as they are excluded from the accessibility tree. So while the modal dialog is open there is no other <h1> to compete with.

    I’m not sure if there is consensus on this because I have seen many examples where an <h2> was used instead.

  • Note - Posted on

    Today I learned, adding tabindex="-1" to skip link targets is likely no longer necessary in modern browsers.

    Manuel Matuzović tested skip links without tabindex="-1" on targets across major browsers and screen readers on macOS, Windows and Android, concluding it is safe to remove in most setups, thanks to sequential focus navigation starting point.

    Furthermore, adding tabindex="-1" to skip link targets also introduces a regression in usability. With tabindex="-1" on main, clicking on any non-interactive area inside main makes main itself the focus starting point. So, the next tab press sends focus to the first focusable element in main, not the next one after where the user clicked. The gov.uk team removed tabindex from main for this reason.

  • Note - Posted on

    Today I learned that setting type="reset" on a <button> element in HTML creates a reset button that, when activated, immediately clears all form data, resetting it to its initial state.

    This could have been useful in the context of a search form. But <input type="search"> already provides a native clear button for that single field.

  • HTML and Typescript.

    Mandy Michael uses a brilliant analogy to explain why developers must get to know the HTML elements available to them and use the appropriate one for their content.

    In TypeScript, we have the concept of an any type. When you assign a type of any it means the content can be anything. […] But if everything is typed as any then you lose the benefits of the language.

    This is the same with HTML. If you use the <div> everywhere, you aren’t making the most of language. Because of this it’s important that you actively choose what the right element is and don’t just use the default <div>.

    This reminded me of the following quote by Jen Simmons from their HTML course:

    HTML syntax itself is fairly simple. The trickier part is knowing which tags to use when.

  • Safari drops support for the theme-color meta tag

    The <meta name="theme-color"> tag is no longer supported in Safari 26 on macOS and iOS.

    If a fixed or sticky element touches the top or bottom edge of the window, then and only then, Safari extends that element’s background color into the corresponding top or bottom bar. Otherwise, on iOS, the bars remain translucent and have no solid color background.

    As Wenson Hseih explained on WebKit Bugzilla:

    A solid background color extension (“top bar tint”) is only needed in cases where there’s a viewport-constrained (fixed or sticky) element near one of the edges of the viewport that borders an obscured content inset (such as the top toolbar on macOS, or compact tab bar on iOS), in order to avoid a gap above or below fixed elements in the page that would otherwise appear when scrolling. This color extension behaviour is more critical on iPhone, where there’s a much “softer” blur effect underneath the browser UI (and so more of the page underneath is otherwise directly visible).

  • Note - Posted on

    I keep forgetting, but the alt attribute of the <img> element is not just useful for users who are visually impaired. It is also useful when the image is not displayed in the browser for whatever reason. For example: the src attribute does not contain a valid path to an image.