{"id":157,"date":"2026-04-07T04:52:43","date_gmt":"2026-04-07T04:52:43","guid":{"rendered":"https:\/\/gigz.pk\/css\/?post_type=lesson&#038;p=157"},"modified":"2026-04-07T04:52:44","modified_gmt":"2026-04-07T04:52:44","slug":"pseudo-classes-hover-and-focus","status":"publish","type":"lesson","link":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/","title":{"rendered":"Pseudo-classes hover and focus"},"content":{"rendered":"\n<p>Pseudo-classes are used in CSS to define a special state of an element. They help you apply styles when a user interacts with a page, such as moving the mouse over a button or clicking into a form field.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is hover<\/h3>\n\n\n\n<p>The hover pseudo-class is applied when a user places their mouse pointer over an element. It is commonly used for buttons, links, and images to improve user experience.<\/p>\n\n\n\n<p>Example of hover<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">button:hover {<br>  background-color: blue;<br>  color: white;<br>}<\/pre>\n\n\n\n<p>In this example, the button changes color when the user moves the mouse over it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What is focus<\/h3>\n\n\n\n<p>The focus pseudo-class is applied when an element is selected or activated, usually when a user clicks on an input field or navigates using the keyboard.<\/p>\n\n\n\n<p>Example of focus<\/p>\n\n\n\n<pre class=\"wp-block-preformatted\">input:focus {<br>  border: 2px solid green;<br>  outline: none;<br>}<\/pre>\n\n\n\n<p>This highlights the input field when the user clicks on it or tabs into it.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Why hover and focus are important<\/h3>\n\n\n\n<p>Hover improves visual feedback and makes interfaces feel interactive. Focus is essential for accessibility, helping users who navigate with keyboards understand which element is active.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Best practices<\/h3>\n\n\n\n<p>Use hover effects to guide users but avoid overusing strong animations. Always include focus styles so that forms and buttons are accessible. Do not remove outlines unless you replace them with a clear visible style.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Practical example<\/h3>\n\n\n\n<pre class=\"wp-block-preformatted\">&lt;!DOCTYPE html&gt;<br>&lt;html&gt;<br>&lt;head&gt;<br>&lt;style&gt;<br>a {<br>  color: black;<br>  text-decoration: none;<br>}a:hover {<br>  color: red;<br>}input {<br>  padding: 8px;<br>}input:focus {<br>  border: 2px solid blue;<br>}<br>&lt;\/style&gt;<br>&lt;\/head&gt;<br>&lt;body&gt;&lt;a href=\"#\"&gt;Hover over this link&lt;\/a&gt;<br>&lt;br&gt;&lt;br&gt;<br>&lt;input type=\"text\" placeholder=\"Click here\"&gt;&lt;\/body&gt;<br>&lt;\/html&gt;<\/pre>\n\n\n\n<p>This example shows how hover changes a link color and focus highlights an input field.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Summary<\/h3>\n\n\n\n<p>The hover and focus pseudo-classes make websites more interactive and user friendly. They are simple to use but very powerful for improving design and accessibility.<\/p>\n\n\n\n<p><\/p>\n","protected":false},"menu_order":0,"template":"","class_list":["post-157","lesson","type-lesson","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.5 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Pseudo-classes hover and focus - CSS learning mastery<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Pseudo-classes hover and focus - CSS learning mastery\" \/>\n<meta property=\"og:description\" content=\"Pseudo-classes are used in CSS to define a special state of an element. They help you apply styles when a user interacts with a page, such as moving the mouse over a button or clicking into a form field. What is hover The hover pseudo-class is applied when a user places their mouse pointer over [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/\" \/>\n<meta property=\"og:site_name\" content=\"CSS learning mastery\" \/>\n<meta property=\"article:modified_time\" content=\"2026-04-07T04:52:44+00:00\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"2 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-classes-hover-and-focus\\\/\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-classes-hover-and-focus\\\/\",\"name\":\"Pseudo-classes hover and focus - CSS learning mastery\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\"},\"datePublished\":\"2026-04-07T04:52:43+00:00\",\"dateModified\":\"2026-04-07T04:52:44+00:00\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-classes-hover-and-focus\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-classes-hover-and-focus\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/lesson\\\/pseudo-classes-hover-and-focus\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Pseudo-classes hover and focus\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/gigz.pk\\\/css\\\/#website\",\"url\":\"https:\\\/\\\/gigz.pk\\\/css\\\/\",\"name\":\"CSS learning mastery\",\"description\":\"\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/gigz.pk\\\/css\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Pseudo-classes hover and focus - CSS learning mastery","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/","og_locale":"en_US","og_type":"article","og_title":"Pseudo-classes hover and focus - CSS learning mastery","og_description":"Pseudo-classes are used in CSS to define a special state of an element. They help you apply styles when a user interacts with a page, such as moving the mouse over a button or clicking into a form field. What is hover The hover pseudo-class is applied when a user places their mouse pointer over [&hellip;]","og_url":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/","og_site_name":"CSS learning mastery","article_modified_time":"2026-04-07T04:52:44+00:00","twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"2 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/","url":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/","name":"Pseudo-classes hover and focus - CSS learning mastery","isPartOf":{"@id":"https:\/\/gigz.pk\/css\/#website"},"datePublished":"2026-04-07T04:52:43+00:00","dateModified":"2026-04-07T04:52:44+00:00","breadcrumb":{"@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/gigz.pk\/css\/lesson\/pseudo-classes-hover-and-focus\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/gigz.pk\/css\/"},{"@type":"ListItem","position":2,"name":"Pseudo-classes hover and focus"}]},{"@type":"WebSite","@id":"https:\/\/gigz.pk\/css\/#website","url":"https:\/\/gigz.pk\/css\/","name":"CSS learning mastery","description":"","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/gigz.pk\/css\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson\/157","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/lesson"}],"about":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/types\/lesson"}],"wp:attachment":[{"href":"https:\/\/gigz.pk\/css\/wp-json\/wp\/v2\/media?parent=157"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}