Category: 5. Helpers

https://cdn3d.iconscout.com/3d/premium/thumb/help-3d-icon-png-download-12031418.png

  • Visually hidden

    This chapter discusses about classes provided by Bootstrap to visually hide any element, such as .visually-hidden and .visually-hidden-focusable.

    • The .visually-hidden class in Bootstrap 5 is used to visually hide an element while keeping it accessible to screen readers and other assistive technologies.
    • The .visually-hidden-focusable class is used to visually hide an element by default, but to display it when its focused, for example, on using a keyboard.
    • The .visually-hidden-focusable class can also be used within a container :focus-within. The container will be displayed when any child element of the container receives focus.

    Test focusability: Use keyboard navigation to test the focusability of elements. Press the Tab key to navigate through the focusable elements and Shift + Tab to move backward.

    Let’s see an example on the usage of the classes .visually-hidden and .visually-hidden-focusable:

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Visually hidden</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Visually hidden</h4><br><br><h4 class="visually-hidden">Hidden title for screen readers</h4><a class="visually-hidden-focusable" href="#content">Skip to home page</a><div class="visually-hidden-focusable">A container with an <a href="#">element that is focusable</a>.</div></body></html>

  • Vertical rule

    This chapter discusses about vertical rule. The custom vertical rule helper creates vertical dividers in common layouts, like the <hr> element.

    • The vertical rule class is denoted as .vr
    • It is 1px wide
    • It has minimum-height of 1em
    • Its color is set using currentColor and opacity

    You can customize the verical rules with additional styles as per your requirement.

    The example given below shows the usage of .vr class:https://www.tutorialspoint.com/bootstrap/examples/vertical_rule_create.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper - Vertical rule</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Vertical rule example</h4><div class="container"><div class="row"><div class="col-md-3 text-bg-light"><p>Text on the left side of vertical divider.</p></div><div class="col-md-1"><hr class="vr"></div><div class="col-md-3 text-bg-light"><p>Text on the right side of vertical divider.</p></div></div></div></body></html>

    In flex layouts, the height of vertical rule adjusts automatically based on the size of its container.

    Let’s see an example where the height of vertical rule is based on the flex layout:https://www.tutorialspoint.com/bootstrap/examples/vertical_rule_flex.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper - Vertical rule</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Vertical rule with flex</h4><div class="d-flex flex-row"><div class="flex-grow-1"><p>Content on the left</p></div><div class="d-flex flex-grow-1" style="height: 200px;"><div class="vr"></div></div><div class="flex-grow-1"><p>Content on the right</p></div></div></body></html>

    Vertical rule with stacks

    Vertical rule can also be used in stacks, to separate the different values.

    Let’s see an example where the vertical rule is used in stacks:https://www.tutorialspoint.com/bootstrap/examples/vertical_rule_stack.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper - Vertical rule</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><link href="https://getbootstrap.com/docs/5.3/assets/css/docs.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Vertical rule with stacks</h4><div class="hstack gap-1"><div class="p-3 text-bg-info">First item</div><div class="vr"></div><div class="p-3 text-bg-primary">Second item</div><div class="vr"></div><div class="p-3 text-bg-warning">Third item</div></div></body></html>

  • Text truncation

    This chapter discusses about the utility provided by Bootstrap that helps in truncating long strings of text. Text truncation is a feature that allows you to truncate long strings of text that overflow their container, and display an ellipsis (…) at the end of the truncated text to indicate that more text is available.

    • This can be useful for situations where you have limited space to display text, such as in a table or card.
    • To truncate text in Bootstrap 5, you can use the .text-truncate class.
    • It requires display: inline-block or display: block.
    • This class can be added to any element that contains text, such as a <div> or a <p> element.

    Here’s an example of how to use the .text-truncate class:https://www.tutorialspoint.com/bootstrap/examples/text_truncation.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Text truncation</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Text truncation example</h4><!-- Block level --><div class="row"><div class="col-3 text-truncate">
    
            The string of text seems to be very long, thus truncating it.
            &lt;/div&gt;&lt;/div&gt;&lt;!-- Inline level --&gt;&lt;span class="d-inline-block text-truncate" style="max-width: 150px;"&gt;
            The string of text seems to be very long, thus truncating it.
        &lt;/span&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Stretched link

    This chapter discusses about the class .stretched-link provided by Bootstrap.

    The .stretched-link class in Bootstrap is used to create a link that stretches to fill the entire parent container.

    • This class can be used on any element that can contain a link, such as a <div> or <a> element, to make the entire element clickable and act as a link.
    • Any element with position:relative and contains a link with the .stretched-link class is clickable.
    • The .stretched-link class cannot be mixed with most table elements.
    • This class can be safely added to cards as they have position:relative by default in Bootstrap.
    • Using stretched links with multiple links and tap targets is not advisable.

    Card with stretched link

    This is useful for cases where you want to make an entire section of content clickable, such as a card or a list item.

    Let’s see an example on the usage of the .stretched-link class in a card:

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Card</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Stretched link in a card</h4><div class="card" style="width: 20rem;"><img src="/bootstrap/images/tutimg.png" class="card-img-top" alt="..."><div class="card-body"><h5 class="card-title">Stretched link in a card</h5><p class="card-text">Here is an example that shows the entire card as a link. This is because of the .stretched-link class of Bootstrap.</p><a href="#" class="btn btn-primary stretched-link">View</a></div></div></body></html>

    You need to add the .position-relative class to prevent the link from stretching outside the parent element, when custom components do not have position: relative by default.

    Let’s see an example on the usage of the .position-relative class:https://www.tutorialspoint.com/bootstrap/examples/stretched_link_custom.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stretched link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Custom component with stretched link</h4><div class="d-flex position-relative"><img src="/bootstrap/images/tutimg.png" class="flex-shrink-0 me-3" alt="..."><div><h5 class="mt-0">Custom component with stretched link using .position-relative</h5><p>Here is an example showing the use of .position-relative class in a component that shows a stretched link usage.</p><a href="#" class="stretched-link">View</a></div></div></body></html>

    Let’s see one more example of the usage of the .position-relative class.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stretched link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Columns with stretched link</h4><div class="row g-0 bg-body-secondary position-relative"><div class="col-md-4 mb-md-0 p-md-4"><img src="/bootstrap/images/tutimg.png" class="w-100" alt="..."></div><div class="col-md-4 p-4 ps-md-0"><h5 class="mt-0">Columns with stretched link</h5><p>Another example of strecthed link with .position-relative on this other custom component. You can use it here to give the component a bit of body and size.</p><a href="#" class="stretched-link">View</a></div></div></body></html>

  • Stacks

    This chapter discusses about stacks. A stack is an utility class that can be used to control the stacking of content within a container.

    The stack utility class controls the stacking order of elements. Stacks offer a quick and easy way of applying the flexbox properties to create layouts in Bootstrap.

    Vertical stack

    The class .vstack is used to create vertical layouts. The utilities such as .gap-* can be used to add space between items.

    By default, the stacked items are full-width.

    The example given below shows the usage of .vstack class:

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Vertical stack example</h4><br><div class="vstack gap-1"><div class="text-bg-secondary p-2">Item on First place</div><div class="text-bg-primary p-2">Item on Second place</div><div class="text-bg-info p-2">Item on Third place</div></div></body></html>

    Stack the buttons or any other elements, using the class .vstack.https://www.tutorialspoint.com/bootstrap/examples/stack_vertical_buttons.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Vertical stack using buttons</h4><br><div class="vstack gap-3 col-md-4 mx-auto"><button type="button" class="btn btn-success">Confirm changes</button><button type="button" class="btn btn-secondary">Cancel</button></div></body></html>

    Horizontal stack

    The class .hstack is used to create horizontal layouts. The utilities such as .gap-* can be used to add space between items.

    By default, the stacked items are vertically centered and only take up their necessary width.

    The example given below shows the usage of .hstack class:https://www.tutorialspoint.com/bootstrap/examples/horizontal_stack.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Horizontal stack example</h4><br><div class="hstack gap-3 column-gap-3"><div class="text-bg-warning p-2">Item one</div><div class="text-bg-light p-2">Item two</div><div class="text-bg-secondary p-2">Item three</div></div></body></html>

    The horizontal margin utility like .ms-auto can be used to add spaces. The utility class .ms-auto aligns the text to the right of the screen. Let’s see an example:https://www.tutorialspoint.com/bootstrap/examples/horizontal_margin.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Horizontal margin example</h4><br><div class="hstack gap-3 column-gap-3"><div class="text-bg-primary p-2">Item one</div><div class="text-bg-secondary p-2">Item two</div><div class="text-bg-info p-2 ms-auto">Item three</div></div></body></html>

    Vertical rules such as the class .vr is used to create a vertical divider. Let’s see an example for the same.

    The example given below shows the usage of .vr class:https://www.tutorialspoint.com/bootstrap/examples/stack_vertical_rule.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Horizontal stack with vertical rule</h4><br><div class="hstack gap-3 column-gap-3"><div class="text-bg-secondary p-3">Item one</div><div class="vr"></div><div class="text-bg-warning p-3">Item two</div><div class="vr"></div><div class="text-bg-info p-3">Item three</div></div></body></html>

    An inline form can be created using the class .hstack.https://www.tutorialspoint.com/bootstrap/examples/stack_horizontal_form.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Stack</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h4>Create an inline form</h4><br><div class="hstack gap-2"><input class="form-control me-auto" type="text" placeholder="Add text here..." aria-label="Add text here..."><div class="vr"></div><button type="button" class="btn btn-success">Submit</button><div class="vr"></div><button type="button" class="btn btn-outline-danger">Clear</button></div></body></html>

  • Ratio

    This chapter discusses about the aspect ratio. In Bootstrap, aspect ratio is used to maintain the proportions of a responsive element, such as an image or video, relative to its parent container. It is specified using the .ratio class along with a modifier class that represents the desired aspect ratio.

    • To manage the aspect ratios of external content like <iframe>s, <embed>s, <video>s, and <object>s, use the ratio-* class.
    • The ratio helper can also be used on standard HTML child element, such as a <div> or <img>
    • The styles are applied from the parent .ratio class directly to the child element.
    • The * in the aspect ratio modifier class can be replaceable with:
      • ratio-21×9: creates a responsive element with a 21:9 aspect ratio
      • ratio-16×9: creates a responsive element with a 16:9 aspect ratio
      • ratio-4×3: creates a responsive element with a 4:3 aspect ratio
      • ratio-1×1: creates a responsive element with a 1:1 aspect ratio

    Here’s an example of how aspect ratios are used with the <iframe> element. Here we are using the 16×9 aspect ratio:https://www.tutorialspoint.com/bootstrap/examples/ratio_16x9.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-success text-center">
    
            Aspect Ratio 16x9
        &lt;/h2&gt;&lt;hr&gt;&lt;div class="ratio ratio-16x9"&gt;&lt;iframe src="https://www.youtube.com/embed/4PWVFBiFVVU"
                    title="YouTube video" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Here's an example of how aspect ratios are used with the <iframe> element. Here we are using the 21x9 aspect ratio:https://www.tutorialspoint.com/bootstrap/examples/ratio_21x9.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h2 class="text-success text-center">
    
            Aspect Ratio - 21x9
        &lt;/h2&gt;&lt;hr&gt;&lt;div class="ratio ratio-21x9"&gt;&lt;iframe src="https://www.youtube.com/embed/4PWVFBiFVVU"
                    title="YouTube video" allowfullscreen&gt;&lt;/iframe&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Custom Ratios

    In Bootstrap, a custom ratio allows you to define your own aspect ratio for a responsive element using a combination of CSS and JavaScript.

    This can be useful if you have a specific aspect ratio that is not covered by the built-in aspect ratio modifier classes. Following example demonstrates by setting --bs-aspect-ratio: 50% on the .ratio.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Ratio</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><h1 class="text-success text-center">
    
    	  Ratio
    </h1><hr><div class="text-center"><h2 class="text-success">Bootstrap 5 Custom ratios</h2></div><br><div class="ratio" style="--bs-aspect-ratio: 10%;"><div class="bg-success"><h1>success</h1></div></div><div class="ratio" style="--bs-aspect-ratio: 30%;"><div class="bg-secondary"><h1>secondary</h1></div></div></body></html>

  • Position

    This chapter discusses about configuration of position of an element.

    Bootstrap provides a set of helper classes to set the position of an element on a page. Some of the classes provided by Bootstrap are as follows:.

    • .fixed-top
    • .fixed-bottom
    • .sticky-top
    • .sticky-bottom

    Let us see examples for each set of classes.

    Fixed top

    The class .fixed-top sets the position of an element at the top of the viewport, from edge to edge.

    This is useful for creating navigation bars or headers that remain visible at the top of the screen even as the user scrolls down.https://www.tutorialspoint.com/bootstrap/examples/position_fixed_top.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Fixed top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><nav class="navbar navbar-expand-lg text-bg-success navbar-dark fixed-top"><div class="container-fluid"><a class="navbar-brand" href="#">Use of .fixed-top class</a></div></nav><div class="container-fluid" style="margin-top:80px"><h4>Position fixed at top</h4><p>The class .fixed-top of Bootstrap sets the position of the element at top of the screen.</p><h1>Scroll down the page to see the position</h1></div></body></html>

    Fixed bottom

    The class .fixed-bottom sets the position of an element at the bottom of the viewport, from edge to edge.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Fixed bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><nav class="navbar navbar-expand-lg text-bg-primary navbar-dark fixed-bottom"><div class="container-fluid"><a class="navbar-brand" href="#">Use of .fixed-bottom class</a></div></nav><div class="container-fluid" style="margin-top:80px"><h4>Position fixed at bottom</h4><p>The class .fixed-bottom of Bootstrap sets the position of the element at the bottom of the page.</p><h1>Scroll down the page to see the position</h1></div></body></html>

    Sticky top

    The class .sticky-top is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.https://www.tutorialspoint.com/bootstrap/examples/position_sticky_top.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Position - Sticky top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><div class="container-fluid mt-3"><h3>Sticky Navbar</h3><p>The class <b>.sticky-top</b> is used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p><p>Scroll down the page to see the effect.</p></div><nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-top"><div class="container-fluid"><a class="navbar-brand" href="#">Sticky top</a></div></nav><div class="container-fluid"><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p></div></body></html>

    Responsive sticky top

    Responsive sticky top classes are used in web design to create a navigation menu or header that sticks to the top of the screen as the user scrolls down the page. This ensures that the navigation menu is always visible and easily accessible, even as the user moves further down the page.

    Some of the responsive sticky top classes provided by Bootstrap are as follows:

    • .sticky-sm-top sticks the position of element(s) to top on small sized viewports
    • .sticky-md-top sticks the position of element(s) to top on medium sized viewports
    • .sticky-lg-top sticks the position of element(s) to top on large sized viewports
    • .sticky-xl-top sticks the position of element(s) to top on extra large sized viewports
    • .sticky-xxl-top sticks the position of element(s) to top on extra extra large sized viewports

    Let us see an example:

    Note: Resize your browser to see the change.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Position - Responsive Sticky top</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style="height:1500px"><div class="container-fluid mt-3"><h3>Sticky Navbar</h3><p>The class <b>.sticky-lg-top</b> is a responsive class, used to create a sticky element that remains at the top of the screen, from edge to edge, but only after you scroll past it.</p><p>Scroll down the page to see the effect.</p></div><nav class="navbar navbar-expand-lg bg-dark navbar-dark sticky-lg-top"><div class="container-fluid"><a class="navbar-brand" href="#">Responsive Sticky top</a></div></nav><div class="container-fluid"><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p><p>Example for .sticky-lg-top class of Bootstrap to set the position of an element, like a navbar, stick to the top of the screen.</p></div></body></html>

    Sticky bottom

    The class .sticky-bottom is used to create a sticky element that remains at the bottom of the screen, from edge to edge, but only after you scroll past it.https://www.tutorialspoint.com/bootstrap/examples/position_sticky_bottom.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - sticky bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style=height:1000px class="d-flex flex-column"><!-- Navbar --><nav class="navbar navbar-expand-lg navbar-light bg-light"><div class="container"><a class="navbar-brand" href="#">Sticky Bottom Example</a></div></nav><!-- Content --><div class="container-fluid flex-grow-1"><h4>sticky bottom</h4><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p></div><!-- Sticky Footer --><footer class="footer text-bg-info py-3 sticky-bottom"><div class="container"><span class="display-6 text-dark">Sticky bottom</span></div></footer></body></html>

    Responsive sticky bottom

    Some of the responsive sticky bottom classes provided by Bootstrap are as follows:

    • .sticky-sm-bottom sticks the position of element(s) to bottom on small sized viewports
    • .sticky-md-bottom sticks the position of element(s) to bottom on medium sized viewports
    • .sticky-lg-bottom sticks the position of element(s) to bottom on large sized viewports
    • .sticky-xl-bottom sticks the position of element(s) to bottom on extra large sized viewports
    • .sticky-xxl-bottom sticks the position of element(s) to bottom on extra extra large sized viewports

    Let us seen an example for a responsive sticky bottom class:

    Note: Resize your browser to see the change.https://www.tutorialspoint.com/bootstrap/examples/position_responsive_sticky_bottom.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html><head><title>Position - Responsive sticky bottom</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body style=height:1000px class="d-flex flex-column"><!-- Navbar --><nav class="navbar navbar-expand-lg navbar-light bg-light"><div class="container"><a class="navbar-brand" href="#">Responsive Sticky Bottom Example</a></div></nav><!-- Content --><div class="container-fluid flex-grow-1"><h4>Responsive sticky bottom</h4><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p><p>Here is an example for responsive sticky bottom. Its a helper class in bootstrap 5.</p></div><!-- Sticky Footer --><footer class="footer text-bg-warning py-3 sticky-lg-bottom"><div class="container"><span class="display-6 text-dark">Sticky bottom</span></div></footer></body></html>

  • Icon link

    This chapter discusses about icon links, through which you can stylize the hyperlinks and other icons.

    In Bootstrap, an icon link is a link that is accompanied by an icon. The icon can be positioned either before or after the link text, and it is typically used to provide additional context or visual cues to the user.

    Icon links can be useful for adding visual interest and interactivity to your website or application, and they can be used in a variety of contexts such as navigation menus, buttons, or calls to action. The default link styles are modified by the icon link helper classes. They automatically align any pairing of icon and text and thus enhance their appearance on the page.

    Bootstrap icons along with any icon or image can be used in the icon links.

    • Icons that are added only with the purpose of decoration, should be hidden from assistive technologies using aria-hidden=”true”.
    • Icons that are added with purpose of conveying some meaning or information, provide an appropriate text alternative by adding role=”img” along with appropriate aria-label.
    https://www.tutorialspoint.com/bootstrap/examples/icon_link.php

    Example

    • To a regular <a> element, add .icon-link
    • Insert an icon on either side of the link text.
    • The .icon-link class will automatically size, place and color the icon.

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="box-seam" viewBox="0 0 16 16"&gt;&lt;path d="M8.186 1.113a.5.5 0 0 0-.372 0L1.846 3.5l2.404.961L10.404 2l-2.218-.887zm3.564 1.426L5.596 5 8 5.961 14.154 3.5l-2.404-.961zm3.25 1.7-6.5 2.6v7.922l6.5-2.6V4.24zM7.5 14.762V6.838L1 4.239v7.923l6.5 2.6zM7.443.184a1.5 1.5 0 0 1 1.114 0l7.129 2.852A.5.5 0 0 1 16 3.5v8.662a1 1 0 0 1-.629.928l-7.185 2.874a.5.5 0 0 1-.372 0L.63 13.09a1 1 0 0 1-.63-.928V3.5a.5.5 0 0 1 .314-.464L7.443.184z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-danger"&gt;Icon link example&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link.&lt;/p&gt;&lt;a class="icon-link" href="#"&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#box-seam"&gt;&lt;/use&gt;&lt;/svg&gt;
    			    	Box Icon with text link
                &lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Let us see another example where icon is placed after the text in an icon link:https://www.tutorialspoint.com/bootstrap/examples/icon_after_link.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="airplane-fill" viewBox="0 0 16 16"&gt;&lt;path d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918-.375 2.253 1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318-.376-2.253-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link example&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the icon is placed after the text in the icon link.&lt;/p&gt;&lt;a class="icon-link" href="#"&gt;Icon after the text
    		    	&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#airplane-fill"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Style on hover

    In order to move the icon in an icon link to right, add the utility class .icon-link-hover to the class .icon-link.

    Let us see an example:https://www.tutorialspoint.com/bootstrap/examples/icon_link_hover.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                            style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="chevron-right" viewBox="0 0 16 16"&gt;&lt;path d="M4.646 1.646a.5.5 0 0 1 .708 0l6 6a.5.5 0 0 1 0 .708l-6 6a.5.5 0 0 1-.708-.708L10.293 8 4.646 2.354a.5.5 0 0 1 0-.708z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;/div&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link example - hover&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the icon moves to the right on hovering.&lt;/p&gt;&lt;a class="icon-link icon-link-hover" href="#"&gt;&lt;strong&gt;Icon link hover&lt;/strong&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#chevron-right"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Utilities

    In order to modify the underline color and offset of the icon link, use the custom link utilities provided by Bootstrap.

    • To add color to the iconlink, use the class link-* (where * can be any color-modes like danger, success, warning, info, etc.)
    • To add color to the line under the iconlink, use the class link-underline-* where * can be any color-modes like danger, success, warning, info, etc.)
    • To add opacity to the line under the iconlink, use the class link-underline-opacity-* (where * can be the percentage number such as 50, 55, 75, etc.)

    Let us see an example of modifying the icon link using the predefined utilities:https://www.tutorialspoint.com/bootstrap/examples/icon_link_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Icon Link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script><link rel="apple-touch-icon" href="/docs/5.3/assets/img/favicons/apple-touch-icon.png" sizes="180x180"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-32x32.png" sizes="32x32" type="image/png"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon-16x16.png" sizes="16x16" type="image/png"><link rel="manifest" href="/docs/5.3/assets/img/favicons/manifest.json"><link rel="mask-icon" href="/docs/5.3/assets/img/favicons/safari-pinned-tab.svg" color="#712cf9"><link rel="icon" href="/docs/5.3/assets/img/favicons/favicon.ico"><link rel="canonical" href="https://icons.getbootstrap.com/icons/search/"><script src="/assets/js/color-modes.js"></script><link rel="stylesheet" href="/assets/font/bootstrap-icons.min.css"><link rel="stylesheet" href="/assets/css/docs.css"></head><body><nav class="navbar navbar-inverse navbar-fixed-top text-bg-light" role="navigation"><div class="container"><div class="navbar-header"><h1 class="logo"><a title="tutorialspoint"><img alt="tutorialspoint" src="http://www.tutorialspoint.com/green/images/logo.png"
    
                                style="height: auto; width: auto; display: inline-block; top: 0px;"&gt;&lt;/a&gt;&lt;/h1&gt;&lt;/div&gt;&lt;/div&gt;&lt;/nav&gt;&lt;div class="container mt-2"&gt;&lt;svg xmlns="http://www.w3.org/2000/svg" style="display: none;"&gt;&lt;symbol id="airplane-fill" viewBox="0 0 16 16"&gt;&lt;path d="M6.428 1.151C6.708.591 7.213 0 8 0s1.292.592 1.572 1.151C9.861 1.73 10 2.431 10 3v3.691l5.17 2.585a1.5 1.5 0 0 1 .83 1.342V12a.5.5 0 0 1-.582.493l-5.507-.918-.375 2.253 1.318 1.318A.5.5 0 0 1 10.5 16h-5a.5.5 0 0 1-.354-.854l1.319-1.318-.376-2.253-5.507.918A.5.5 0 0 1 0 12v-1.382a1.5 1.5 0 0 1 .83-1.342L6 6.691V3c0-.568.14-1.271.428-1.849Z"&gt;&lt;/path&gt;&lt;/symbol&gt;&lt;/svg&gt;&lt;div class="feature col"&gt;&lt;h3 class="fs-2 text-success"&gt;Icon link customization&lt;/h3&gt;&lt;p&gt;Icon link feature of Bootstrap allows a user to add an icon along with an hyperlink and even the icon works as a link. Here the appearance of icon link is modified using the link utility classes.&lt;/p&gt;&lt;a class="icon-link icon-link-hover link-danger link-underline-success link-underline-opacity-55" href="#"&gt;&lt;strong&gt;Icon link utility&lt;/strong&gt;&lt;svg class="bi" aria-hidden="true"&gt;&lt;use xlink:href="#airplane-fill"&gt;&lt;/use&gt;&lt;/svg&gt;&lt;/a&gt;&lt;/div&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

  • Focus ring

    This chapter discusses about adding and modifying custom focus ring styles to various elements and components.

    In Bootstrap 5, the focus ring is a visual indicator that appears around an element when it receives focus. The focus ring is a circular outline that appears around the element, typically in a contrasting color, to indicate that the element is currently active and ready to receive input from the user.

    Bootstrap 5 provides a built-in focus ring that is applied to interactive elements such as buttons, links, and form controls by default.

    The default outline on :focus is removed by the helper class .focus-ring, thus replacing it with a box-shadow.

    Let’s see an example showing the usage of .focus-ring:https://www.tutorialspoint.com/bootstrap/examples/focus_ring.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-bg-light border rounded-2">
    
          Example focus ring
        &lt;/a&gt;&lt;button class="button focus-ring py-1 px-2 text-bg-light border rounded-2"&gt;Click Me&lt;/button&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Customize focus ring

    Focus ring can be customized using the CSS variables, Sass variables, utilities, or custom styles.

    CSS variables

    In order to change the default appearance of a focus ring, modify the CSS variables --bs-focus-ring-*

    Let's see an example of customizing the CSS variables --bs-focus-ring-*:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_CSS.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize CSS variable</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-color: rgba(var(--bs-danger-rgb), .25)">
    
          Red focus ring
        &lt;/a&gt;&lt;div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Let's see an example of customizing the CSS variables --bs-focus-ring-* in order to make the focus ring blurry:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_CSS_blur.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize CSS variable</h4><a href="#" class="d-inline-flex focus-ring py-1 px-2 text-decoration-none border rounded-2" style="--bs-focus-ring-x: 20px; --bs-focus-ring-y: 20px; --bs-focus-ring-blur: 6px">
    
          Blur focus ring
        &lt;/a&gt;&lt;/div&gt;&lt;/body&gt;&lt;/html&gt;</pre>

    Utilities

    Bootstrap provides several utilities .focus-ring-* to modify the default settings.

    For example, modify the color of the focus ring with any of the theme colors.

    Let's see an example of customizing the utility .focus-ring-*:https://www.tutorialspoint.com/bootstrap/examples/focus_ring_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap Helper</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container-fluid flex-grow-1"><h4>Focus ring - Customize utilities</h4><p><a href="#" class="d-inline-flex focus-ring focus-ring-success py-1 px-2">Success focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-info py-1 px-2">Info focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-warning py-1 px-2">Warning focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-danger py-1 px-2">Danger focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-secondary py-1 px-2">Secondary focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-primary py-1 px-2">Primary focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-dark py-1 px-2">Dark focus ring</a></p><p><a href="#" class="d-inline-flex focus-ring focus-ring-light py-1 px-2">Light focus ring</a></p></div></body></html>

  • Colored links

    This chapter discusses about the colored link feature of helper classes. The Bootstrap 5 colored links are used to add colors to the link elements.

    In order to make the links colored, use .link-* classes. These classes have :hover and :focus states, unlike the .text-* classes.

    In order to make the links legible, that have relatively light foreground color, use them on a dark background.

    .link-body-emphasis is the only colored link that is unique and high contrast link color. It comes with :hover and :focus styles.

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Colored link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container p-2"><h4>Colored links</h4><br><p><a href="#" class="link-primary">Primary Color Link</a></p><p><a href="#" class="link-secondary">Secondary Color Link</a></p><p><a href="#" class="link-info">Info Color Link</a></p><p><a href="#" class="link-success">Success Color Link</a></p><p><a href="#" class="link-light bg-dark">Light Color Link on dark background</a></p><p><a href="#" class="link-dark">Dark Color Link</a></p><p><a href="#" class="link-warning">Warning Color Link</a></p><p><a href="#" class="link-danger">Danger Color Link</a></p><p><a href="#" class="link-body-emphasis">Custom Emphasis Link</a></p></div></body></html>

    Accessibility tip: Use of color just provides a visual indication, and this will not be helpful to users of assistive technologies like screen readers. Make sure that the meaning is clear from the content itself.

    Use alternative means to add clarity to the content using the .visually-hidden class.

    Link utilities

    Bootstrap provides a range of link utilities such as link opacity, link offset, underline color, underline opacity, and so on.

    Similarly colored links can also be modified using the link utilities. Let us see an example:https://www.tutorialspoint.com/bootstrap/examples/colored_link_utilities.php

    Example

    You can edit and try running this code using the Edit & Run option.

    <!DOCTYPE html><html lang="en"><head><title>Bootstrap - Helper - Colored link</title><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0"><link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"><script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"></script></head><body><div class="container p-2"><h4>Colored link utilities</h4><br><p><a href="#" class="link-offset-1 link-primary link-opacity-50 link-underline-warning link-underline-opacity-75">Primary Color Link</a></p><p><a href="#" class="link-offset-1 link-secondary link-opacity-50 link-underline-danger link-underline-opacity-50">Secondary Color Link</a></p><p><a href="#" class="link-offset-2 link-info link-opacity-25 link-underline-success link-underline-opacity-100">Info Color Link</a></p><p><a href="#" class="link-offset-2 link-success link-opacity-75 link-underline-danger link-underline-opacity-70">Success Color Link</a></p></div></body></html>