EN
HTML - get focus on div element
10
points
In this short article we would like to show how to get focus on div element in HTML.
Quick solution:
add
tabindex="0"
attribute to thediv
element.
Practical example
In the below example we use :focus
pseudo class only to show the div
element is focused.
// ONLINE-RUNNER:browser;
<!doctype html>
<html>
<body>
<style>
div:focus {
outline: 3px solid #b2d2f0;
}
</style>
<div tabindex="0">Click me to get focus!</div>
<div tabindex="0">Click me to get focus!</div>
<div tabindex="0">Click me to get focus!</div>
</body>
</html>