Author: Amber Colvin

  • How to Open an HTML Link in a New Tab

    How to Open an HTML Link in a New Tab

    To open an HTML link in a new tab, add the target=”_blank” attribute to a normal anchor. Keep the destination in href, then place the visible link text between the opening and closing a tags. This pattern requests a new browsing context without JavaScript and works for ordinary text navigation.

    The browser or the user’s settings ultimately determine whether that new context appears as a tab or a window. Therefore, target=”_blank” requests the behavior; it does not guarantee a particular piece of browser interface.

    How to Open an HTML Link in a New Tab: The Complete Anchor Example

    Use this complete anchor when the link should request a separate browsing context:

    <a href=”https://example.com/resources” target=”_blank” rel=”noopener”>Open the resource</a>

    The href attribute contains the destination URL. The target attribute controls where the browser requests that destination, and _blank names a new, unnamed browsing context. The words “Open the resource” become the clickable link text.

    rel=”noopener” is a useful companion for links that open another document. It prevents the newly opened page from using the opener reference to interact with the original page. It does not create the new tab; target=”_blank” makes that request.

    How Does target=”_blank” Change Navigation?

    Without a target attribute, a link normally loads its href in the current browsing context. With target=”_blank”, the browser asks for a new top-level context instead. In common desktop configurations, that context appears as a new tab, while some configurations open a new window.

    • The original page remains available in its existing tab or window.
    • The destination loads in the newly requested context.
    • The browser may apply popup-blocking, tab preferences, or other user controls.

    The keyword _blank does not force a physical tab. A browser or user setting ultimately decides whether the result is a tab or a window. Keyboard commands and accessibility preferences can also affect how a link opens. The HTML declares the requested browsing context, not the final interface choice.

    How Do You Use an HTML href to Open a Link in a New Tab?

    An href for a new tab is still an ordinary URL paired with target=”_blank”. Apply the same pattern to text links, product names, documentation references, or any other element that users expect to activate as a link:

    <a href=”/documentation” target=”_blank” rel=”noopener”>Read the documentation</a>

    For an image link, place the image element inside the anchor and keep the same attributes on the anchor:

    <a href=”/gallery” target=”_blank” rel=”noopener”><img src=”/images/gallery-preview.jpg” alt=”View the image gallery”></a>

    The image becomes clickable because it is nested inside the a element. Provide meaningful alt text so users who cannot see the image still understand the link’s purpose. The anchor’s href remains the destination, while its target requests the separate context.

    When Is Same-Tab Navigation Clearer?

    Same-tab navigation is often clearer when the destination is part of the same task or site journey. It preserves the browser’s normal back-button flow and avoids accumulating extra tabs. Omit the target attribute for the default behavior, or state it explicitly:

    <a href=”/account” target=”_self”>Open your account</a>

    • Use same-tab navigation for related pages, form steps, account areas, and primary site content.
    • Request a new context for supporting resources that users may need to consult while keeping the current page open.
    • Describe the destination clearly so users can choose how they want to open it.

    Use target=”_blank” deliberately rather than on every link. The clearer choice depends on whether preserving the current page helps the user complete the task.

  • HTML dialog: Modal and Non-Modal Examples

    HTML dialog: Modal and Non-Modal Examples

    Use the native HTML dialog element to build a modal or non-modal interface without recreating its focus and keyboard behavior with a generic div. The example below is a complete HTML dialog with two triggers, a method=dialog form, and JavaScript for opening and closing it.

    When a dialog is shown, the element receives the open state. The opening method determines whether the rest of the page remains interactive.

    Create an HTML dialog box with a form close action

    Place the trigger buttons and dialog in the document. A form with method=”dialog” closes its nearest dialog when a submit button is activated. The clicked button’s value becomes the dialog’s return value.

    Markup: <button type=”button” id=”open-modal”>Open modal</button> <button type=”button” id=”open-nonmodal”>Open non-modal</button> <dialog id=”account-dialog”> <form method=”dialog”> <h2>Account settings</h2> <p>Choose an action for this account.</p> <button value=”cancel”>Cancel</button> <button value=”save”>Save</button> </form> </dialog>

    The two buttons use type=”button” so they do not submit a surrounding form. The dialog’s Cancel and Save buttons are submit controls for the dialog form, so either one closes the dialog without requiring a custom click handler.

    Open an HTML5 dialog with show() or showModal()

    Call show() for non-modal behavior. The dialog opens, but users can still interact with the rest of the page. Call showModal() for modal behavior. The browser renders a backdrop, keeps interaction inside the dialog, and manages modal focus.

    JavaScript: const dialog = document.querySelector(“#account-dialog”); const modalButton = document.querySelector(“#open-modal”); const nonModalButton = document.querySelector(“#open-nonmodal”); modalButton.addEventListener(“click”, () => { dialog.showModal(); }); nonModalButton.addEventListener(“click”, () => { dialog.show(); });

    • show() opens the dialog without making the document modal.
    • showModal() opens it as a modal dialog and enables ::backdrop styling.
    • Both methods set dialog.open to true. Do not call either method again while the same dialog is already open.

    Close the dialog, handle events, and read a return value

    Pressing Escape on a modal dialog normally fires the cancel event and then closes the dialog. Listen for cancel when you need to prevent that default behavior, such as when unsaved changes require confirmation. The close event fires after any closing method, including a dialog-form submission.

    Use close(value) to close the element from JavaScript. Its optional value is exposed through dialog.returnValue. The form buttons above return cancel or save.

    Closing and events: dialog.addEventListener(“cancel”, (event) => { /* event.preventDefault() keeps it open */ }); dialog.addEventListener(“close”, () => { console.log(dialog.returnValue); }); dialog.close(“programmatic”);

    After close(), the open property becomes false. The close event is the suitable place to update the page based on the selected value, while the cancel event is the suitable place to intercept Escape before the default close occurs.

    Style the HTML dialog and its ::backdrop

    Target the dialog directly for its panel appearance. The ::backdrop pseudo-element applies to the viewport layer created by showModal(); a non-modal dialog does not receive that modal backdrop.

    CSS: dialog { border: 0; border-radius: 0.5rem; padding: 1.5rem; max-width: 32rem; } dialog::backdrop { background: rgb(0 0 0 / 55%); }

    Keep the close controls inside the dialog form when their purpose is to return a user-selected result. Use close(value) for programmatic outcomes that are not represented by a form button.

  • HTML fieldset: Group Related Form Controls with legend and CSS

    HTML fieldset: Group Related Form Controls with legend and CSS

    An HTML fieldset groups form controls that belong to one topic, while a legend names that group. This gives screen-reader users a clear question or category before they encounter the controls. Build the semantic structure first, then use CSS to add the visual boundary, spacing, and layout.

    The HTML fieldset tag is especially useful for radio buttons because the shared name makes the inputs one-choice controls, while the legend identifies what that choice answers.

    How does an HTML fieldset group related controls?

    Place related controls inside fieldset and put the group label in its first child, legend. Unlike a heading styled to look similar, legend is programmatically associated with the fieldset. Each control still needs its own label. Connect a label’s for value to the input’s unique id, so clicking the text also selects or focuses the control.

    Use one name for mutually exclusive radio buttons, and give every option a distinct value. Do not use placeholder text as a substitute for a label: placeholders disappear and do not identify a completed choice reliably.

    How does the HTML fieldset tag work in a radio-button form?

    This complete radio-button form includes the group label, three individually labelled options, and a submit control:

    Complete markup: <form action=”/preferences” method=”post”> <fieldset> <legend>Contact preference</legend> <input type=”radio” id=”email” name=”contact” value=”email” required> <label for=”email”>Email</label> <input type=”radio” id=”phone” name=”contact” value=”phone”> <label for=”phone”>Phone</label> <input type=”radio” id=”none” name=”contact” value=”none”> <label for=”none”>No contact</label> </fieldset> <button type=”submit”>Save preference</button> </form>

    The legend, “Contact preference,” labels the entire group. Each label identifies one answer, and the matching for and id attributes preserve that relationship even if the visual layout changes. The shared contact name lets the browser enforce a single radio selection. The required attribute on one radio makes choosing an option mandatory for the group.

    How do you disable an entire fieldset?

    Add the disabled attribute to the fieldset opening tag when the whole group is unavailable:

    Disabled group: <fieldset disabled> <legend>Contact preference (unavailable)</legend> … </fieldset>

    Disabled fieldset controls cannot receive focus or user input, and their values are not submitted with the form. The legend remains readable, which allows the group’s status to be communicated. Keep important explanatory text in the legend or nearby content rather than placing interactive controls inside the legend.

    How do you style a CSS fieldset?

    Use a CSS fieldset rule for the border, padding, and internal layout. Style legend separately because browsers apply their own default border placement and spacing:

    CSS: fieldset { border: 2px solid #b8c0cc; padding: 1rem; display: grid; gap: .5rem; max-inline-size: 24rem; } legend { padding-inline: .5rem; font-weight: 700; } fieldset label { display: flex; align-items: center; gap: .5rem; }

    The border creates the visual group, while padding keeps controls away from its edge. The grid display and gap property provide consistent vertical spacing without adding presentational markup. The label rule aligns each radio button with its text and enlarges the useful click area. Adjust the border color, thickness, and maximum width to match the surrounding form while keeping sufficient contrast.

  • CSS scrollbar style: Customize color, width, track, and thumb

    CSS scrollbar style: Customize color, width, track, and thumb

    A practical CSS scrollbar style uses standardized properties first, then adds browser-specific selectors when you need precise control over the track, thumb, or hover state. The standard layer works across modern Firefox and Chromium-based browsers; WebKit pseudo-elements provide finer visual control where supported.

    Apply the rules to the element that owns the scrolling area. Styling the scrollbar changes its appearance, not the way users scroll with a wheel, touchpad, keyboard, or touch input.

    CSS scrollbar style: Start with standardized color and width

    Set scrollbar-color and scrollbar-width

    scrollbar-color accepts the thumb color first and the track color second. scrollbar-width supports auto, thin, and none. Use none only when another visible scrolling method is available.

    Example: .scroll-panel { scrollbar-color: #52606d #e8edf2; scrollbar-width: thin; }

    These properties are the preferred baseline for a scrollbar CSS style because they are standardized rather than tied to one rendering engine.

    Know what Firefox and Chromium support

    Firefox uses these standardized properties as its main scrollbar styling interface. Current Chromium-based browsers also support them, while older Chromium versions may require the WebKit layer below. Keep the standard declarations in your stylesheet so browsers that do not understand WebKit selectors still receive a useful color and width.

    Scrollbar CSS style: Style the track and thumb with WebKit pseudo-elements

    WebKit scrollbar pseudo-elements are a separate compatibility layer, not a universal cross-browser standard. They are useful in Chromium-based browsers and WebKit-based browsers such as Safari, while Firefox relies on the standardized properties.

    Target the WebKit scrollbar, track, and thumb

    ::-webkit-scrollbar controls the scrollbar’s width and height. ::-webkit-scrollbar-track styles the channel behind the thumb, and ::-webkit-scrollbar-thumb styles the draggable control. A border on the thumb can create visual spacing between it and the track.

    Example: .scroll-panel::-webkit-scrollbar { width: 12px; height: 12px; } .scroll-panel::-webkit-scrollbar-track { background: #e8edf2; } .scroll-panel::-webkit-scrollbar-thumb { background: #52606d; border: 3px solid #e8edf2; border-radius: 999px; }

    Use hover styles without changing scroll behavior

    Change only visual properties for interaction feedback. Example: .scroll-panel::-webkit-scrollbar-thumb:hover { background: #334e68; } This makes the thumb easier to identify without changing overflow, dimensions, or scrolling mechanics.

    Custom scrollbar CSS for one overflow container

    Attach rules to a named scrolling element

    Give the intended container a class, then apply both standard and WebKit rules to that class. Example markup: <div class=”scroll-panel”>Long content goes here.</div>

    The complete custom scrollbar CSS can be written as: .scroll-panel { max-height: 18rem; overflow: auto; scrollbar-color: #52606d #e8edf2; scrollbar-width: thin; } .scroll-panel::-webkit-scrollbar { width: 12px; height: 12px; } .scroll-panel::-webkit-scrollbar-track { background: #e8edf2; } .scroll-panel::-webkit-scrollbar-thumb { background: #52606d; border: 3px solid #e8edf2; border-radius: 999px; } .scroll-panel::-webkit-scrollbar-thumb:hover { background: #334e68; }

    Keep overflow, height, and width declarations separate

    The max-height and overflow: auto declarations create the scrolling area; the scrollbar rules only style it. Use overflow-x and overflow-y separately when horizontal and vertical behavior must differ. Avoid applying these selectors to * unless every scrollbar on the page should match.

    HTML scrollbar styling: Build fallbacks and interaction states

    Let standard rules remain the fallback

    Place scrollbar-color and scrollbar-width on the scrolling element first, followed by WebKit pseudo-elements. Firefox will use the standard rules, while compatible Chromium and WebKit browsers can use the more detailed track and thumb declarations.

    Test contrast, keyboard scrolling, and hover feedback

    Keep the thumb visibly distinct from the track in its normal and hover states. Test long content with keyboard focus, including arrow keys, Page Up, Page Down, Home, and End. On touch devices, do not rely on hover feedback; the scrollbar should remain understandable and usable without it.

  • overflow: hidden Explained: Clipping, Scrolling, and Layout

    overflow: hidden Explained: Clipping, Scrolling, and Layout

    overflow: hidden clips content that extends beyond an element’s padding box. It does not remove that content from the document; it only prevents the overflowing portion from being painted outside the element.

    Developers often shorten the name to overflow hidden. The valid CSS declaration is overflow: hidden, and it takes effect when the element has content that exceeds a constrained width or height. If the box can grow naturally to fit its contents, there may be nothing to clip.

    What does overflow: hidden do?

    The overflow property controls content that does not fit inside a box. With overflow: hidden, the browser clips the excess at the padding edge. The border remains visible, while text, child elements, backgrounds, shadows, or other painted content extending beyond that edge may be cut off.

    The declaration applies to both horizontal and vertical overflow. Use overflow-x or overflow-y when only one axis should be clipped. A hidden overflow area does not display user-facing scrollbars, but the content can still exist in layout and can usually be reached by script by changing properties such as scrollTop or scrollLeft.

    How does a fixed-size box show clipping?

    A fixed-size box makes the effect clear because its content cannot expand the box. This example gives the element a 220-pixel outer width and an 80-pixel outer height:

    CSS: .card { width: 220px; height: 80px; padding: 16px; box-sizing: border-box; overflow: hidden; }

    Markup: <div class=”card”>This content is deliberately long enough to exceed the available height of the card and continue below its padding edge.</div>

    Only the portion that fits inside the card is visible. The remaining text still belongs to the element, so it can affect layout calculations and remain available to browser APIs. Reducing the height or adding more content makes the clipping easier to observe.

    Without a constrained height, a normal block usually expands vertically and displays all of its content. This is why overflow hidden should not be used as a universal fix for an unrelated sizing or layout defect. First establish which dimension is meant to remain constrained.

    When should you choose visible, auto, scroll, or clip?

    • visible: The default value. Content can paint outside the element’s box, which is useful for badges, menus, or shadows that must extend beyond their parent. It does not provide scrolling or clipping.
    • hidden: Clips excess content and shows no scrollbars. It suits decorative cropping, controlled panels, and boxes where inaccessible overflow is intentional. Hidden overflow can still be scrolled programmatically.
    • auto: Clips overflow and provides scrolling when the content requires it. This is usually the practical choice for a panel, log, or text region whose content must remain reachable without forcing a scrollbar when the box is short.
    • scroll: Provides a scrolling mechanism even when the content currently fits. Choose it when a stable scrollbar area matters for layout or when users should immediately recognize that more content may be available.
    • clip: Clips content like hidden but does not allow scrolling, including programmatic scrolling. It also does not establish a block formatting context. Use it for deliberate, permanent clipping when the overflow must not be scrollable.

    How does CSS overflow: hidden affect layout and focus?

    On a block container, overflow: hidden establishes a block formatting context. This changes how the element interacts with floats and margin collapsing and can contain floated descendants within the box. The same formatting-context behavior is also associated with values such as auto and scroll, but not clip. If clipping and a formatting context are both needed with clip, use an explicit layout value such as display: flow-root.

    Clipping does not equal removal. A clipped descendant remains in the DOM and may still be focusable. A keyboard user could tab to a link or form control positioned outside the visible area, while its focus outline is clipped or difficult to see. Do not assume that hidden overflow removes an item from the tab order or makes it inaccessible to scripts.

    For interactive content that must remain reachable, use auto or a layout that keeps the control visible. Reserve hidden for content that is intentionally cropped, and test focus movement, keyboard navigation, and responsive dimensions whenever descendants can extend beyond the padding box.

  • HTML main: How to Mark Up Primary Page Content

    HTML main: How to Mark Up Primary Page Content

    The HTML main element identifies the dominant content unique to the current document. Put the page’s article, product details, search results, dashboard view, or other primary task inside <main>; keep repeated site chrome outside it. The element also exposes a main landmark to assistive technology.

    Use one non-hidden main landmark at a time. A page can contain several main elements in its source when inactive views are hidden, but users should normally encounter only one exposed main landmark.

    What belongs in the HTML main element?

    Content belongs in the HTML main element when it distinguishes this document or view from other pages on the site. It should answer the page’s primary purpose rather than describe the surrounding website.

    • An article page’s heading, publication details, body, and related in-article sections.
    • A product page’s product information, pricing, specifications, and purchase controls.
    • A search page’s search heading, filters that control the results, and result list.
    • A dashboard’s active report, task area, or application view.

    The main element may contain headings, paragraphs, lists, forms, articles, sections, and other elements needed to present that content. A page-specific sidebar can belong inside <main> when it directly supports the document, while a repeated site-wide sidebar generally belongs outside it.

    A complete page structure: where main content fits

    Place <main> inside <body>, alongside the page’s repeated structural landmarks. A compact structure looks like this:

    <body> <header>Site identity</header> <nav>Primary links</nav> <main>Unique page content</main> <aside>Related site content</aside> <footer>Site information</footer> </body>

    • Header: identifies the site or page and may contain branding or introductory material.
    • Navigation: provides links for moving through the site or application.
    • Main: contains the document’s dominant, page-specific content.
    • Aside: contains tangential or supporting content, such as related links.
    • Footer: contains closing information, legal links, or repeated contact details.

    For an article, the article heading and text usually sit inside <main>. An article-specific header can sit inside the article, while the site header remains a sibling of main.

    How HTML main differs from header, nav, aside, and footer

    These elements describe different structural responsibilities. Location alone does not determine whether content belongs in main.

    • <header> introduces a site, page, article, or section. A site-wide header is repeated boilerplate, not the page’s main content.
    • <nav> groups navigation links. Primary menus, account menus, and breadcrumb navigation should not be placed in main merely because they appear above the content.
    • <aside> holds content related to, but separate from, the primary flow. A recurring “Most popular” panel or advertising block usually belongs outside main.
    • <footer> provides closing information for the site, page, article, or section. A repeated site footer does not become main content.

    Use <section> inside main for a thematic group that needs its own heading. Use <article> for a self-contained item, such as a post or product review. The main element is the broader landmark that contains the page’s primary experience.

    Can hidden views expose more than one HTML main element at once?

    Normally, expose only one non-hidden HTML main element at a time. Assistive technology uses the main landmark as a shortcut to the primary content, so multiple simultaneously exposed main landmarks can create ambiguity.

    Application shells and single-page interfaces may keep several views in the document. In that case, keep the active view in one main element and hide inactive views with the HTML hidden state or an equivalent accessibility-safe mechanism. For example, an inactive view can be represented as <main hidden>, while the active view remains exposed.

    • Do not leave several alternate screens visible and mark each one as main.
    • Do not rely only on visual positioning to hide an inactive landmark from assistive technology.
    • When switching views, remove the hidden state from the new main view before exposing it and hide the previous one.

    If the application uses one persistent main landmark and swaps its contents, that also satisfies the one-visible-main pattern.

  • Footer HTML: Complete Examples for Pages and Articles

    Footer HTML: Complete Examples for Pages and Articles

    Footer HTML marks supporting information for the nearest page or section. Use one document-level footer for site-wide details, or place a footer inside an article when the information belongs specifically to that article.

    The element provides meaning, not a fixed visual position. CSS determines whether the footer stays in normal flow, appears at the bottom of a layout, or changes position at a particular viewport width.

    What does footer HTML represent, and does it set a visual position?

    The footer element represents closing or supporting content for its nearest sectioning context. At page scope, it describes information about the whole document. Inside an article, it describes information about that article. Inside another sectioning element, such as section, it belongs to that section.

    A footer tag HTML example is interpreted by this surrounding structure; the element does not automatically mean “the bottom of the screen.” It can contain copyright information, related links, author details, publication dates, contact information, or other content associated with its scope.

    A document footer does not have to be the final child of the body. Place it where the document structure and reading order make sense, then use CSS for spacing, alignment, columns, backgrounds, or fixed positioning.

    How should a document-level footer be marked up with site information and navigation?

    Use a document-level footer for information that supports the entire site or page. Site identification, a navigation list, legal links, and general contact details are appropriate examples. The following footer HTML code shows those items together:

    <footer> <p>&copy; 2025 Example Journal</p> <nav aria-label=”Footer navigation”> <ul> <li><a href=”/about”>About</a></li> <li><a href=”/privacy”>Privacy</a></li> <li><a href=”/contact”>Contact</a></li> </ul> </nav> <address>Email: <a href=”mailto:[email protected]”>[email protected]</a></address> </footer>

    The nav element identifies the group as navigation, while the list organizes its links. The address element is suitable for contact information related to the site or its owner. A footer can contain several navigation groups, but each group should have a clear purpose and accessible label.

    For a page-specific shell, the same structure can sit after the main content inside a wrapper. Its scope remains document-level if it is not nested inside an article or another sectioning context.

    When should you use the HTML footer tag inside an article for author metadata?

    Use an article footer when the information describes the article rather than the whole site. Common content includes the author, publication date, update date, categories, tags, licensing information, or links to related article resources.

    This example shows an article footer with author metadata:

    <article> <h2>Choosing Accessible Color Contrast</h2> <p>Readable contrast supports visitors across devices and lighting conditions.</p> <footer> <p>Written by Maya Chen</p> <p>Published on January 12, 2025; updated on February 3, 2025</p> </footer> </article>

    Here, the inner footer belongs to the article because it is nested within the article element. A separate site footer can still appear outside the article and provide global navigation or contact details. Do not use an article footer merely to force content below the article with CSS.

    What belongs in footer HTML code, including contact details?

    Choose footer content according to scope:

    • Document scope: site name, copyright notice, global navigation, privacy links, accessibility information, and general contact details.
    • Article scope: author name, publication or update dates, categories, tags, licensing details, and article-specific related links.
    • Section scope: supporting information that applies only to that section, such as a section editor or a link to its complete archive.

    Keep the structure meaningful. Use paragraphs for short notices, lists for groups of links, and navigation markup for a distinct navigation region. Contact details can appear in an address element when they identify the relevant site, organization, or author. A footer supplies semantics and reading structure; it does not create columns, a sticky bar, a bottom alignment, or any other visual treatment without CSS.

  • CSS white-space: Predict Spaces and Line Wrapping

    CSS white-space: Predict Spaces and Line Wrapping

    CSS white-space controls whether the browser collapses runs of HTML white space, preserves source line breaks, and wraps text at the edge of its container. The main choices are normal, nowrap, pre, pre-wrap, and pre-line.

    Use the same sample to predict each result. The source contains two spaces between “Alpha” and “Beta,” followed by a source line break before “Gamma.”

    What Does CSS white-space Do to a Text Sample?

    The white-space property changes two related behaviors: how sequences of spaces and line breaks are rendered, and whether the browser may wrap text onto another line. It does not add visual spacing as a layout technique; it defines how existing text whitespace is interpreted.

    Use this sample source throughout:

    Sample source: Alpha Beta
    Gamma

    With the default behavior, the browser renders the sample as one space between “Alpha” and “Beta,” and the source line break does not create a new rendered line. Other values can preserve the two spaces, preserve the line break, prevent wrapping, or combine those behaviors.

    How Does HTML white space Collapse by Default?

    In ordinary HTML flow, adjacent spaces, tabs, and source line breaks are treated as collapsible whitespace. A sequence of these characters usually becomes one rendered space. Whitespace at the beginning or end of a line can also disappear.

    That means this source:

    Alpha Beta
    Gamma

    normally displays as “Alpha Beta Gamma.” The newline in the HTML source is not the same as an explicit line break element. To force a break in ordinary text, use an intentional break or a CSS value that preserves line breaks.

    Wrapping is separate from collapsing. Even after several whitespace characters become one space, the browser can wrap the resulting text when the containing element is too narrow. The normal value enables both collapsing and wrapping.

    When Should You Use white-space nowrap?

    Use white-space nowrap when text must stay on one line, such as a compact navigation label, status badge, button caption, or table-cell value. The declaration is white-space: nowrap;.

    nowrap collapses spaces and source line breaks like normal, but it prevents automatic wrapping. The sample therefore remains “Alpha Beta Gamma” on one line rather than breaking between words when the container narrows.

    Preventing wrapping can cause overflow. A long label, URL, or generated value may extend beyond its container, become clipped, create horizontal scrolling, or push against adjacent content, depending on the element’s overflow rules. Check narrow screens and translated text before applying it broadly. If content must remain readable, allow wrapping or add a deliberate overflow strategy instead of hiding the excess.

    How Does the white-space property Compare These Values: normal, nowrap, pre, pre-wrap, and pre-line?

    These values produce predictable differences with the same sample:

    • normal: Collapses repeated spaces and source line breaks, then allows wrapping. The sample becomes “Alpha Beta Gamma.”
    • nowrap: Collapses repeated spaces and source line breaks, but prevents automatic wrapping. The sample stays on one line.
    • pre: Preserves repeated spaces and line breaks, but prevents wrapping. The two-space gap remains, the break before “Gamma” remains, and long lines can overflow.
    • pre-wrap: Preserves repeated spaces and line breaks while allowing wrapping. This keeps the sample’s formatting but lets long content move to additional lines.
    • pre-line: Collapses repeated spaces but preserves source line breaks and allows wrapping. The gap becomes one space, while “Gamma” starts on its own line.

    Choose normal for typical paragraphs, nowrap for short one-line UI text, pre for faithfully formatted content that may overflow, pre-wrap for formatted content that must remain readable in narrow containers, and pre-line when line breaks matter but repeated spacing does not.

  • CSS Links: Style Colors, States, and Underlines

    CSS Links: Style Colors, States, and Underlines

    Use one base rule for CSS links, then add state selectors and decoration changes in a deliberate order. This CSS link underline approach keeps links recognizable while allowing hover, keyboard focus, and activation to provide distinct feedback.

    The most reliable pattern preserves an underline by default, changes color for visited and interactive states, and uses a visible outline for keyboard focus.

    Style CSS links by default with a working rule set

    Start with the a selector so every link receives a consistent baseline. The :link selector then targets unvisited links, while :visited provides a separate history-based color.

    a { color: #1455cc; text-decoration-line: underline; text-decoration-thickness: 0.12em; text-underline-offset: 0.18em; text-decoration-color: currentColor; }

    a:link { color: #1455cc; }

    a:visited { color: #6b3fa0; }

    a:hover { color: #0b6b52; text-decoration-thickness: 0.16em; }

    a:active { color: #a33a00; }

    a:focus-visible { color: #1455cc; outline: 3px solid #b54708; outline-offset: 3px; text-decoration-thickness: 0.18em; }

    These rules assume links have an href attribute. The base rule establishes the default appearance, and each later state can adjust only the properties needed for that interaction.

    Apply CSS link states in the right order

    CSS link states can overlap. A link may be visited and hovered at the same time, or focused and briefly active during keyboard activation. When selectors have equal specificity, the later declaration wins for the same property.

    • :link styles an unvisited link.
    • :visited styles a link whose destination appears in the browser’s history.
    • :hover applies while a pointer rests over the link. It is not a dependable touch interaction.
    • :active applies during the moment the link is being activated.
    • :focus-visible applies when the browser determines that focus should be visibly indicated, especially for keyboard navigation.

    Place the base a rule first, followed by :link, :visited, :hover, :active, and :focus-visible. Putting :focus-visible last lets the keyboard-focus treatment remain visible when another state also matches. This order is more important when several rules set the same color, underline thickness, or other property.

    Customize a CSS link underline with text-decoration

    A CSS link underline is controlled most precisely with separate text-decoration properties rather than a single shorthand declaration. The working rule uses these four controls:

    • text-decoration-line: underline adds the line. Use none only when another strong link cue remains.
    • text-decoration-thickness: 0.12em sets the line weight relative to the link’s font size.
    • text-underline-offset: 0.18em creates space between the glyphs and the line, improving clarity.
    • text-decoration-color: currentColor makes the underline follow the link’s current text color.

    Use a separate decoration color when the design needs stronger contrast between text and underline. For example, text-decoration-color: #b54708 can make a CSS underline link more noticeable without changing its text color. Keep the underline on ordinary inline links; removing it everywhere makes links harder to distinguish from surrounding copy.

    Keep underlines in CSS links distinct for hover and keyboard focus

    Hover and keyboard focus serve different users, so do not treat them as interchangeable CSS link states. A thicker underline or color shift works well for pointer hover. Keyboard users need a persistent, high-contrast focus indicator that does not depend on pointer position.

    Keep the default underline during focus and add an outline with outline and outline-offset. The outline sits outside the text and remains easy to see against varied backgrounds. Do not replace it with a subtle color change alone, and do not write outline: none without providing an equally clear alternative.

    Because :focus-visible follows :active in the rule set, its outline and thickness remain available when a keyboard user activates the link. The result is a CSS underline link that stays recognizable at rest, responds clearly to hover, and preserves visible keyboard focus.

  • text-transform: capitalize in CSS: Uppercase, Lowercase, and None

    text-transform: capitalize in CSS: Uppercase, Lowercase, and None

    Use the text-transform CSS property to change how text appears without editing the text in your HTML. Its main values are uppercase, lowercase, capitalize, and none.

    Choose uppercase for labels or controls that should display every letter in capitals. Choose capitalize when each word should begin with a capital letter. The choice changes presentation only; it does not rewrite the underlying text.

    How do you make text uppercase with CSS?

    To make text uppercase with CSS, apply text-transform: uppercase to the target element:

    .button-label { text-transform: uppercase; }

    If the HTML contains Submit application, the browser displays SUBMIT APPLICATION. The rule affects letters in the rendered content, including text inside headings, links, buttons, and other elements.

    You can apply the rule to a reusable class:

    .all-caps {
    text-transform: uppercase;
    }

    Then add that class to any element that needs the same treatment. This approach keeps the source text readable and avoids typing duplicate all-capital versions into your HTML.

    What does text-transform: capitalize do?

    The text-transform: capitalize value capitalizes the first letter of each word:

    .title { text-transform: capitalize; }

    The source text monthly design report appears as Monthly Design Report. Capitalize is different from uppercase: it does not convert an entire string to uppercase.

    It also does not necessarily create perfect editorial title case. For example, a source value such as MONTHLY design report may display as MONTHLY Design Report, because the property targets word initials rather than first lowercasing the rest of the string. If your content requires a specific style for acronyms, short words, or mixed-case names, provide that casing in the source text or transform it with application logic.

    How do lowercase, none, and inheritance work?

    Use lowercase when every displayed letter should be small:

    .email { text-transform: lowercase; }

    For example, [email protected] displays as [email protected]. To remove a transformation from an element, use none:

    .plain-text { text-transform: none; }

    text-transform is inherited. A parent rule can therefore affect descendants even when those child elements have no text-transform declaration:

    .card { text-transform: uppercase; }

    Every text element inside .card can display in uppercase. Override that inherited value on a child by declaring another value:

    .card .description { text-transform: none; }

    The description then uses its normal source casing while other card content remains uppercase. If the override does not work, check whether another selector has greater specificity or whether a later rule wins in the cascade.

    Does text-transform change the original text value?

    No. CSS text transformation changes rendering, not the stored string. If the HTML contains Download report, the browser can display DOWNLOAD REPORT with text-transform: uppercase, but the text node still contains Download report.

    This distinction matters for links, accessibility, scripts, and forms. JavaScript reading an element’s text still receives the original value, and a form submits the input’s actual value rather than its visually transformed version. An input styled with text-transform: uppercase may look like ABC123 while its value remains the characters the user entered.

    Use CSS for visual consistency. Change the underlying string separately when the stored or submitted casing must also change.