In Bootstrap 4, the class .focus
is used in conjunction with the pseudo-class :focus
.
Here's an example:
.btn:focus, .btn.focus {
outline: 0;
box-shadow: 0 0 0 0.2rem rgba(0, 123, 255, 0.25);
}
The rationale behind this approach?
The main purpose is to maintain consistency across different browsers.
Styling form elements and buttons can be tricky due to browsers sometimes not following styling rules for these elements or applying their own styles. Browsers that ignore the :focus
pseudo-class may still adhere to the styling rules of the .focus
class because it is considered a "real" class rather than a pseudo-class.
This reasoning underscores the importance of using the .focus
class.
This prevents any changes in button appearance from occurring.
It's important to note that the focus class/pseudo-class only affects the outline (or the box-shadow acting as the outline) of the button, and nothing else.