{"id":42980,"date":"2018-01-23T23:01:00","date_gmt":"2018-01-23T15:01:00","guid":{"rendered":"https:\/\/www.hongkiat.com\/blog\/?p=42980"},"modified":"2018-04-09T17:09:31","modified_gmt":"2018-04-09T09:09:31","slug":"count-html-state-change","status":"publish","type":"post","link":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/","title":{"rendered":"Count HTML State Changes Real-Time with CSS"},"content":{"rendered":"<p><strong>Counting is a ubiquitous task<\/strong> in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many donut flavors are bagged in the shopping cart? All are crucial questions users deserve answers for.<\/p>\n<p>So, this post will show you how to <strong>count bi-stated elements<\/strong>, which constitute the majority of user controls such as checkboxes and text inputs, <strong>using CSS counters<\/strong>.<\/p>\n<p>You need to <strong>target those states with CSS first<\/strong>, which is possible by means of<strong> pseudo-classes and HTML attributes<\/strong> that allow us to do just that. Go ahead and experiment with the idea and explore the different pseudo-classes that can indicate the change in a state of an element, dynamically.<\/p>\n<p>We\u2019ll start with the simplest, checkboxes.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/definite-guide-css-pseudoclasses\/\">The Definitive Guide to CSS Pseudo-Classes<\/a><\/p>\n<h2>1. Checkboxes<\/h2>\n<p>Checkboxes go into \u201cchecked\u201d state when they\u2019re ticked. The <code>:checked<\/code> pseudo-class <strong>indicates the checked state<\/strong>.<\/p>\n<pre>\r\n&lt;input type=checkbox&gt; checkbox #1&lt;br&gt;\r\n&lt;input type=checkbox&gt; checkbox #2&lt;br&gt;\r\n&lt;input type=checkbox&gt; checkbox #3&lt;br&gt;\r\n\r\n&lt;br&gt;Checked: &lt;b id=tickedBoxCount&gt;&lt;\/b&gt;\r\n&lt;br&gt;Unchecked: &lt;b id=unTickedBoxCount&gt;&lt;\/b&gt;\r\n<\/pre>\n<pre>\r\n::root{\r\n  counter-reset: tickedBoxCount, unTickedBoxCount;\r\n}\r\ninput[type='checkbox']{\r\n  counter-increment: unTickedBoxCount;\r\n}\r\ninput[type='checkbox']:checked{\r\n  counter-increment: tickedBoxCount;\r\n}\r\n#tickedBoxCount::before{\r\n  content: counter(tickedBoxCount);\r\n}\r\n#unTickedBoxCount::before{\r\n  content: counter(unTickedBoxCount);\r\n}\r\n<\/pre>\n<p>Like I said before, this case is very simple. We <strong>set two counters at the root element<\/strong> and increment each for every checkbox for its two states, respectively. The counter values are then <strong>displayed in a designated place using <code>content<\/code> property<\/strong>.<\/p>\n<p>If you want to understand better <strong>how CSS counters work<\/strong>, have a look at <a href=\"https:\/\/www.hongkiat.com\/blog\/css-automatic-numbering\/\">our previous post<\/a>.<\/p>\n<p>Below, you can see the final result. When you check and uncheck the checkboxes, the values of the \u201cChecked\u201d and \u201cUnchecked\u201d counters are <strong>modified real-time<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg\" alt=\"Counting checkboxes real-time\" width=\"800\" height=\"350\"><\/figure>\n<h2>2. Text inputs<\/h2>\n<p>We can also count how many text inputs <strong>have been filled<\/strong> and how many <strong>have been left empty<\/strong> by the user. This solution won\u2019t be as straightforward as the previous one, because, unlike checkboxes, <strong>text inputs don\u2019t have pseudo-classes<\/strong> to flag when they\u2019re filled.<\/p>\n<p>So, we need to find an alternate route. There\u2019s a pseudo-class that <strong>indicates when an element has placeholder text<\/strong>; it\u2019s called <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/CSS\/:placeholder-shown\" target=\"_blank\"><code>:placeholder-shown<\/code><\/a>.<\/p>\n<p>If we use placeholders in our text input, we can know when the input field is empty. This happens when the user <strong>has not yet typed anything into it<\/strong> because the placeholder will disappear when that happens.<\/p>\n<pre>\r\n&lt;input type=text placeholder='placeholder text'&gt;&lt;br&gt;\r\n&lt;input type=text placeholder='placeholder text'&gt;&lt;br&gt;\r\n&lt;input type=text placeholder='placeholder text'&gt;&lt;br&gt;\r\n\r\n&lt;br&gt; Filled: &lt;b id=filledInputCount&gt;&lt;\/b&gt;\r\n&lt;br&gt; Empty: &lt;b id=emptyInputCount&gt;&lt;\/b&gt;\r\n<\/pre>\n<pre>\r\n::root{\r\n  counter-reset: filledInputCount, emptyInputCount;\r\n}\r\ninput[type='text']{\r\n  counter-increment: filledInputCount;\r\n}\r\ninput[type='text']:placeholder-shown{\r\n  counter-increment: emptyInputCount;\r\n}\r\n#filledInputCount::before{\r\n  content: counter(filledInputCount);\r\n}\r\n#emptyInputCount::before{\r\n  content: counter(emptyInputCount);\r\n}\r\n<\/pre>\n<p>The result is similar to the previous one\u2014the two counters are <strong>automatically incremented and decremented<\/strong> as we add or remove text to or from the input fields.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/text.jpg\" alt=\"Counting text inputs real-time\" width=\"800\" height=\"352\"><\/figure>\n<h2>3. Details<\/h2>\n<p>Alternate states of an element don\u2019t always have to be indicated only by pseudo-classes. There might be <strong>HTML attributes doing that job<\/strong>, like in the case of the <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/HTML\/Element\/details\" target=\"_blank\"><code>&lt;details&gt;<\/code><\/a> element.<\/p>\n<p>The <code>&lt;details&gt;<\/code> element <strong>displays the contents of its <code>&lt;summary&gt;<\/code> child element<\/strong>. When the user clicks that, other contents of the <code>&lt;details&gt;<\/code> element <strong>become visible<\/strong>. Note that <code>&lt;summary&gt;<\/code> element <strong>always needs to come first<\/strong> among the children of <code>&lt;details&gt;<\/code>.<\/p>\n<p>So, <code>&lt;details&gt;<\/code> <strong>has two states<\/strong>: open and closed. The open state is indicated by the <strong>presence of the <code>open<\/code> HTML attribute in the element<\/strong>. This attribute can be targeted in CSS u<strong>sing its attribute selector<\/strong>.<\/p>\n<pre>\r\n&lt;details&gt;\r\n  &lt;summary&gt;Q1: question #1&lt;\/summary&gt;\r\n  &lt;p&gt;answer #1&lt;\/p&gt;\r\n&lt;\/details&gt;\r\n&lt;details&gt;\r\n  &lt;summary&gt;Q2: question #2&lt;\/summary&gt;\r\n  &lt;p&gt;answer #2&lt;\/p&gt;\r\n&lt;\/details&gt;\r\n&lt;details&gt;\r\n  &lt;summary&gt;Q3: question #3&lt;\/summary&gt;\r\n  &lt;p&gt;answer #3&lt;\/p&gt;\r\n&lt;\/details&gt;\r\n&lt;br&gt;\r\n&lt;br&gt; Open: &lt;b id=openDetailCount&gt;&lt;\/b&gt;\r\n&lt;br&gt; Closed: &lt;b id=closedDetailCount&gt;&lt;\/b&gt;\r\n<\/pre>\n<pre>\r\n::root{\r\n  counter-reset: openDetailCount, closedDetailCount;\r\n}\r\ndetails{\r\n  counter-increment: closedDetailCount;\r\n}\r\ndetails[open]{\r\n  counter-increment: openDetailCount;\r\n}\r\n#closedDetailCount::before{\r\n  content: counter(closedDetailCount);\r\n}\r\n#openDetailCount::before{\r\n  content: counter(openDetailCount);\r\n}\r\n<\/pre>\n<p>The result is <strong>two real-time CSS-counters<\/strong> again: Open and Closed.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/detail.jpg\" alt=\"Counting details real-time\" width=\"800\" height=\"321\"><\/figure>\n<h2>4. Radio buttons<\/h2>\n<p>Counting radio buttons require a different technique. We could certainly use the <code>:checked<\/code> pseudo-class we used for checkboxes. However, radio buttons are <strong>used differently than checkboxes<\/strong>.<\/p>\n<p>Radio buttons are <strong>meant to be in groups<\/strong>. The user can select only one inside a group. Each group acts as a single unit. The two states a radio button group can have is either <strong>one of the buttons is selected<\/strong> or <strong>none of them are selected<\/strong>.<\/p>\n<p>Thus, we shouldn\u2019t count radio buttons by individual buttons, but <strong>by button groups<\/strong>. To achieve that, we <strong>make use of the <code>:nth-of-type<\/code> selector<\/strong>. I\u2019ll explain it later; let\u2019s see the code first.<\/p>\n<pre>\r\n&lt;input type=radio name='radio-1'&gt;radio-1.1\r\n&lt;input type=radio name='radio-1'&gt;radio-1.2\r\n&lt;input type=radio name='radio-1'&gt;radio-1.3\r\n&lt;br&gt;\r\n&lt;input type=radio name='radio-2'&gt;radio-2.1\r\n&lt;input type=radio name='radio-2'&gt;radio-2.2\r\n&lt;input type=radio name='radio-2'&gt;radio-2.3\r\n&lt;br&gt;\r\n&lt;input type=radio name='radio-3'&gt;radio-2.1\r\n&lt;input type=radio name='radio-3'&gt;radio-2.2\r\n&lt;input type=radio name='radio-3'&gt;radio-2.3\r\n&lt;br&gt;\r\n&lt;br&gt; Selected: &lt;b id=selectedRadioCount&gt;&lt;\/b&gt;\r\n&lt;br&gt; Unselected: &lt;b id=unSelectedRadioCount&gt;&lt;\/b&gt;\r\n<\/pre>\n<p>We need to <strong>assign the same name<\/strong> to the radio buttons in the same group. Each group in the code above has three radio buttons inside.<\/p>\n<pre>\r\n::root{\r\n  counter-reset: selectedRadioCount, unSelectedRadioCount;\r\n}\r\ninput[type='radio']:nth-of-type(3n){\r\n  counter-increment: unSelectedRadioCount;\r\n}\r\ninput[type='radio']:nth-of-type(3n):checked{\r\n  counter-increment: selectedRadioCount;\r\n}\r\ninput[type='radio']:not(:nth-of-type(3n)):checked{\r\n  counter-increment: unSelectedRadioCount -1 selectedRadioCount;\r\n}\r\n#selectedRadioCount::before{\r\n  content: counter(selectedRadioCount);\r\n}\r\n#unSelectedRadioCount::before{\r\n  content: counter(unSelectedRadioCount);\r\n}\r\n<\/pre>\n<p>The first three style rules in the above snippet are the same as the ones we applied to checkboxes, except, instead of targeting <em>every<\/em> radio button, <strong>we target the last radio button in each group<\/strong>, which is the third one in our case (<code>:nth-of-type(3n)<\/code>). So, we don\u2019t count all the radio buttons but <strong>only one per group<\/strong>.<\/p>\n<p>However, that won\u2019t give us a correct real-time result, as we <strong>have not yet given any rule for counting the other two radio buttons in the group<\/strong>. If one of them is checked it should be counted & the unchecked result should decrease at the same time.<\/p>\n<p>This is why we <strong>add a <code>-1<\/code> value<\/strong> after <code>unSelectedRadioCount<\/code> in the last style rule that targets the other two radio buttons in a group. When one of them is checked, <code>-1<\/code> will <strong>decrease the unchecked result<\/strong>.<\/p>\n<figure><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/radio.jpg\" alt=\"Counting radio button real-time\" width=\"800\" height=\"304\"><\/figure>\n<h2>The Placement of Counts<\/h2>\n<p>You can only see the correct result <strong>after the counting has been finished<\/strong>, i.e. after all the elements that are to be counted have been processed. This is why we need to place the element inside which we\u2019ll display the counters <strong>only after the elements to be counted<\/strong> in the HTML source code.<\/p>\n<p>You may not want to show the counters below the elements but somewhere else on the page. In this case, you <strong>need to reposition the counters<\/strong> using CSS properties such as <code>translate<\/code>, <code>margin<\/code>, or <code>position<\/code>.<\/p>\n<p>But, my suggestion would be to <strong>use the CSS Grid<\/strong> so that you can create the layout of your page <strong>independent of the order of its elements in the HTML source code<\/strong>. For instance, you can easily create a grid that places the counters above or next to the input fields.<\/p>\n<p class=\"note\"><strong>Read Also:<\/strong> <a target=\"_blank\" href=\"https:\/\/www.hongkiat.com\/blog\/css-grid-layout-module\/\">Introduction to the CSS Grid Layout Module<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many donut flavors are bagged in the shopping cart? All are crucial questions users deserve answers for. So, this post will show you how to count bi-stated elements, which&hellip;<\/p>\n","protected":false},"author":145,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[3392],"tags":[507,4501],"topic":[4520],"class_list":["entry-content","is-maxi"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v22.8 (Yoast SEO v27.4) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>Count HTML State Changes Real-Time with CSS - Hongkiat<\/title>\n<meta name=\"description\" content=\"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Count HTML State Changes Real-Time with CSS\" \/>\n<meta property=\"og:description\" content=\"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/\" \/>\n<meta property=\"og:site_name\" content=\"Hongkiat\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/hongkiatcom\" \/>\n<meta property=\"article:published_time\" content=\"2018-01-23T15:01:00+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2018-04-09T09:09:31+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg\" \/>\n<meta name=\"author\" content=\"Preethi Ranjit\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:site\" content=\"@hongkiat\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Preethi Ranjit\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/\"},\"author\":{\"name\":\"Preethi Ranjit\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\"},\"headline\":\"Count HTML State Changes Real-Time with CSS\",\"datePublished\":\"2018-01-23T15:01:00+00:00\",\"dateModified\":\"2018-04-09T09:09:31+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/\"},\"wordCount\":895,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/count-html-state-change\\\/checkbox.jpg\",\"keywords\":[\"CSS\",\"CSS Tutorials\"],\"articleSection\":[\"Coding\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/\",\"name\":\"Count HTML State Changes Real-Time with CSS - Hongkiat\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/count-html-state-change\\\/checkbox.jpg\",\"datePublished\":\"2018-01-23T15:01:00+00:00\",\"dateModified\":\"2018-04-09T09:09:31+00:00\",\"description\":\"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#primaryimage\",\"url\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/count-html-state-change\\\/checkbox.jpg\",\"contentUrl\":\"https:\\\/\\\/assets.hongkiat.com\\\/uploads\\\/count-html-state-change\\\/checkbox.jpg\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/count-html-state-change\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Count HTML State Changes Real-Time with CSS\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"name\":\"Hongkiat\",\"description\":\"Tech and Design Tips\",\"publisher\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#organization\",\"name\":\"Hongkiat.com\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"contentUrl\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/wp-content\\\/uploads\\\/hkdc-logo-rect-yoast.jpg\",\"width\":1200,\"height\":799,\"caption\":\"Hongkiat.com\"},\"image\":{\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/hongkiatcom\",\"https:\\\/\\\/x.com\\\/hongkiat\",\"https:\\\/\\\/www.pinterest.com\\\/hongkiat\\\/\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/#\\\/schema\\\/person\\\/e981676afae36d1ff5feb75094950ab3\",\"name\":\"Preethi Ranjit\",\"description\":\"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.\",\"url\":\"https:\\\/\\\/www.hongkiat.com\\\/blog\\\/author\\\/preethi\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"Count HTML State Changes Real-Time with CSS - Hongkiat","description":"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many","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:\/\/www.hongkiat.com\/blog\/count-html-state-change\/","og_locale":"en_US","og_type":"article","og_title":"Count HTML State Changes Real-Time with CSS","og_description":"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many","og_url":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/","og_site_name":"Hongkiat","article_publisher":"https:\/\/www.facebook.com\/hongkiatcom","article_published_time":"2018-01-23T15:01:00+00:00","article_modified_time":"2018-04-09T09:09:31+00:00","og_image":[{"url":"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg","type":"","width":"","height":""}],"author":"Preethi Ranjit","twitter_card":"summary_large_image","twitter_creator":"@hongkiat","twitter_site":"@hongkiat","twitter_misc":{"Written by":"Preethi Ranjit","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#article","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/"},"author":{"name":"Preethi Ranjit","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3"},"headline":"Count HTML State Changes Real-Time with CSS","datePublished":"2018-01-23T15:01:00+00:00","dateModified":"2018-04-09T09:09:31+00:00","mainEntityOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/"},"wordCount":895,"commentCount":0,"publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg","keywords":["CSS","CSS Tutorials"],"articleSection":["Coding"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/","url":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/","name":"Count HTML State Changes Real-Time with CSS - Hongkiat","isPartOf":{"@id":"https:\/\/www.hongkiat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#primaryimage"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#primaryimage"},"thumbnailUrl":"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg","datePublished":"2018-01-23T15:01:00+00:00","dateModified":"2018-04-09T09:09:31+00:00","description":"Counting is a ubiquitous task in web applications. How many unread emails do you have? How many tasks are left unchecked on your to-do list? How many","breadcrumb":{"@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#primaryimage","url":"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg","contentUrl":"https:\/\/assets.hongkiat.com\/uploads\/count-html-state-change\/checkbox.jpg"},{"@type":"BreadcrumbList","@id":"https:\/\/www.hongkiat.com\/blog\/count-html-state-change\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.hongkiat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Count HTML State Changes Real-Time with CSS"}]},{"@type":"WebSite","@id":"https:\/\/www.hongkiat.com\/blog\/#website","url":"https:\/\/www.hongkiat.com\/blog\/","name":"Hongkiat","description":"Tech and Design Tips","publisher":{"@id":"https:\/\/www.hongkiat.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.hongkiat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/www.hongkiat.com\/blog\/#organization","name":"Hongkiat.com","url":"https:\/\/www.hongkiat.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","contentUrl":"https:\/\/www.hongkiat.com\/blog\/wp-content\/uploads\/hkdc-logo-rect-yoast.jpg","width":1200,"height":799,"caption":"Hongkiat.com"},"image":{"@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/hongkiatcom","https:\/\/x.com\/hongkiat","https:\/\/www.pinterest.com\/hongkiat\/"]},{"@type":"Person","@id":"https:\/\/www.hongkiat.com\/blog\/#\/schema\/person\/e981676afae36d1ff5feb75094950ab3","name":"Preethi Ranjit","description":"A .NET developer with a JavaScript background, Preethi is expert in front-end coding, JavaScript, HTML, and CSS.","url":"https:\/\/www.hongkiat.com\/blog\/author\/preethi\/"}]}},"jetpack_featured_media_url":"https:\/\/","jetpack_shortlink":"https:\/\/wp.me\/p4uxU-bbe","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/42980","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/users\/145"}],"replies":[{"embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/comments?post=42980"}],"version-history":[{"count":1,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/42980\/revisions"}],"predecessor-version":[{"id":42981,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/posts\/42980\/revisions\/42981"}],"wp:attachment":[{"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/media?parent=42980"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/categories?post=42980"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/tags?post=42980"},{"taxonomy":"topic","embeddable":true,"href":"https:\/\/www.hongkiat.com\/blog\/wp-json\/wp\/v2\/topic?post=42980"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}