InfoHeap
Tech tutorials, tips, tools and more
Navigation
  • Home
  • Tutorials
    • CSS tutorials & examples
    • CSS properties
    • Javascript cookbook
    • Linux/Unix Command Line
    • Mac
    • PHP
      • PHP functions online
      • PHP regex
    • WordPress
  • Online Tools
    • Text utilities
    • Online Lint Tools
search

CSS selectors

    Simple Selectors

    • type selectors
    • universal selector (*)
    • attribute presence and value selectors
    • attribute substring selectors
    • class selectors
    • two classes (.c1.c2)
    • id selectors

    Pseudo-classes

    • :link
    • :visited
    • :hover
    • :active
    • :focus
    • :target
    • :lang
    • :enabled and :disabled
    • :checked
    • :root
    • :nth-child
    • :nth-of-type
    • :nth-child vs :nth-of-type
    • :nth-last-child
    • :nth-last-of-type
    • :first-child
    • :first-of-type
    • :last-child
    • :last-of-type
    • :only-child
    • :only-of-type
    • :empty
    • :not

    Pseudo-elements

    • ::first-line
    • ::first-letter
    • ::before and ::after
    • ::placeholder

    Combinators

    • child vs descendant selector
    • adjacent sibling selector (E1 + E2)
    • general sibling selector (E1 ~ E2)

    Specificity

    • Selector specificity
     
    • Home
    • > Tutorials
    • > CSS
    • > CSS selectors

    CSS pseudo class :focus

    on Apr 6, 2016

    The :focus pseudo-class applies while an element has the focus. There can be various ways to get focus on an element. Some of these are:

    • Mouse click (e.g. textarea, input)
    • Tab key
    • Javascript code

    Example – css :focus

    This example reduces font-size to 0.9em when a link gets clicked. Note that click does not reload the page as we are adding hash fragment in url.

    <style type="text/css">
    :focus {
      background-color: lightgreen;
    }
    </style>
    <p>Use tab or click to change focus<p>
    <input type="text" value="text1" autofocus>
    <input type="button" value="button1">
    <a href="#target1">link1</a><br/>
    
    refresh done
    try it online

    Related

    • CSS pseudo class :link - style for unvisited links
    • CSS pseudo class :visited - style for visited links
    • CSS pseudo class :hover
    • CSS pseudo class :active

    Specification

    • W3C CSS 3 :focus pseudo class specification

    Suggested posts:

    1. CSS pseudo class :active
    2. CSS pseudo class :target
    3. CSS pseudo class :hover
    4. AngularJS ng-focus example
    5. CSS :not – negation pseudo-class
    6. CSS pseudo class :link – style for unvisited links
    7. CSS pseudo class :lang
    8. CSS pseudo class :visited – style for visited links
    Share this article: share on facebook share on linkedin tweet this submit to reddit
    Posted in Tutorials | Tagged CSS, CSS selectors, Tutorials

    Follow InfoHeap

    facebook
    twitter
    googleplus
    • Browse site
    • Article Topics
    • Article archives
    • Recent Articles
    • Contact Us
    • Omoney
    Popular Topics: Android Development | AngularJS | Apache | AWS and EC2 | Bash shell scripting | Chrome developer tools | CSS | CSS cookbook | CSS properties | CSS Pseudo Classes | CSS selectors | CSS3 | CSS3 flexbox | Devops | Git | HTML | HTML5 | Java | Javascript | Javascript cookbook | Javascript DOM | jQuery | Kubernetes | Linux | Linux/Unix Command Line | Mac | Mac Command Line | Mysql | Networking | Node.js | Online Tools | PHP | PHP cookbook | PHP Regex | Python | Python array | Python cookbook | SEO | Site Performance | SSH | Ubuntu Linux | Web Development | Webmaster | Wordpress | Wordpress customization | Wordpress How To | Wordpress Mysql Queries

    Copyright © 2023 InfoHeap.

    Powered by WordPress