<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Serhii Babich</title>
    <description>The latest articles on DEV Community by Serhii Babich (@babichweb).</description>
    <link>https://dev.to/babichweb</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F651510%2Fe17f9768-faad-45fa-836b-c8365bac6a51.jpeg</url>
      <title>DEV Community: Serhii Babich</title>
      <link>https://dev.to/babichweb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/babichweb"/>
    <language>en</language>
    <item>
      <title>Mythbusting DOM: Is DOM the same as HTML?</title>
      <dc:creator>Serhii Babich</dc:creator>
      <pubDate>Fri, 05 Jul 2024 15:21:03 +0000</pubDate>
      <link>https://dev.to/babichweb/mythbusting-dom-is-dom-the-same-as-html-561f</link>
      <guid>https://dev.to/babichweb/mythbusting-dom-is-dom-the-same-as-html-561f</guid>
      <description>&lt;p&gt;One of the misconceptions circulating among the young generation of web developers, and not only them, is the belief that the DOM is actually the same HTML, just in the browser. This misconception is further fueled by the fact that the browser's DOM inspector displays everything within the webpage as the good old hypertext markup, adding more confusion to the understanding of these things.&lt;/p&gt;

&lt;p&gt;So, as I loudly declare today: "DOM is not HTML.", the question arises, "What is it, then?" Let's try to figure it out together.&lt;/p&gt;

&lt;p&gt;First, let's look at the dry academic definition. DOM (Document Object Model) is a programming interface that allows programs to dynamically access and update a document's content, structure, and styles. The DOM represents the document as a data structure, such as a tree, where each node is an object representing a part of the document, such as an element, attribute, or text content. Does this make a bit more sense? If you answered "yes," then I have every reason to suspect you have a bit of a pedant in you who loved "Legends and Myths of Ancient Greece" as a favourite book in kindergarten. Wait, that's about me... Oh, never mind, let's try to explain it more simply.&lt;/p&gt;

&lt;p&gt;Let's imagine that HTML tags are images of LEGO blocks, and HTML attributes in this example are different characteristics of these images: colour, orientation in space, etc. Then our HTML documents are those instruction booklets from which you can assemble what's illustrated, like the Millennium Falcon, and then, if desired and inspired, a deep-sea pterodactyl with a pedal drive and a nuclear warhead in its butt.&lt;/p&gt;

&lt;p&gt;And the DOM is what you've assembled from the real blocks, which you can touch with your hands. As in a construction set, each part, a DOM node, is a piece of a complex hierarchy, simultaneously having conventionally parental and child structures. You can imagine this hierarchy in various ways, so for simplification, let's imagine that our LEGO is at least four-dimensional and can simultaneously have both flat and spatial relationships.&lt;/p&gt;

&lt;p&gt;Just as you can find the necessary part in the already assembled constructor (well, when you were assembling and realized three packets ago that you missed inserting the green block), you can also find the required element in the DOM. Moreover, you can find many different elements simultaneously based on various attributes, usually id, tag name, class, attribute value, and others.&lt;/p&gt;

&lt;p&gt;Moreover, you can not only find these elements but also perform various useful actions with them! For instance, you can replace some blocks with others, add new ones, remove unnecessary ones, and even change the properties of these blocks. In a real constructor, this wouldn't work, but if it did, then you could. After all, we have an imaginary, four-dimensional LEGO, so let it be.&lt;/p&gt;

&lt;p&gt;And just like a real LEGO constructor, the DOM can be genuinely interactive, i.e., it can respond to user actions. Just like in those expensive sets where you can assemble a working Lamborghini model at a 1:24 scale, with a beeping horn, a buzzing engine, opening-closing doors, and imaginary cocaine spilt on the passenger seat. I'm talking about DOM events here, not cocaine, but the fact that the DOM can handle events. For example, you press a hypothetical door, and it opens. So it is in the DOM — you press a button, an event is triggered, and you can subscribe to it, opening hypothetical doors. There are many events in the DOM, and all of them are very interesting, and now you can even create your custom events, not limited to standard ones.&lt;/p&gt;

&lt;p&gt;So what am I saying? The DOM is not HTML but a completely separate thing that has a whole range of properties unique to it, and thanks to them, we can create attractive, interesting, and diverse web applications.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>Mythbusting DOM: Was DOM Invented Alongside HTML?</title>
      <dc:creator>Serhii Babich</dc:creator>
      <pubDate>Wed, 03 Jul 2024 07:15:24 +0000</pubDate>
      <link>https://dev.to/babichweb/mythbusting-dom-was-dom-invented-alongside-html-3fme</link>
      <guid>https://dev.to/babichweb/mythbusting-dom-was-dom-invented-alongside-html-3fme</guid>
      <description>&lt;p&gt;There is a common belief that the DOM emerged simultaneously with HTML and has always been an integral part of web development, with developers having tools for dynamic manipulation of HTML elements from the very beginning. However, this is far from the truth. In reality, nearly a decade passed between the emergence of HTML and the creation of the DOM! How did this come about?&lt;/p&gt;

&lt;p&gt;It's undeniable that the web's development in the mid-90s progressed at an explosive rate. Just imagine — only four years passed from the creation of the first web page by Tim Berners-Lee to the launch of amazon.com. By 1996, the internet had become so widespread that the first promotional website for a movie, Space Jam, was launched.&lt;/p&gt;

&lt;p&gt;However, web development itself was still quite primitive, with a very limited set of tools that couldn't keep up with the rapid industry growth. Consider this — the second numbered version of HTML appeared in 1995 (there wasn't officially a first version), JavaScript's first version was developed in the same year, and CSS1 was released in December 1996. Amidst all this, the DOM was still a distant prospect.&lt;/p&gt;

&lt;p&gt;So what prompted the community to create a unified standard? In the mid-90s, the so-called First Browser War was in full swing, with two giants of the time, Netscape Navigator and Internet Explorer, battling it out. In the fight for market share, developers came up with new tricks and features, exacerbating the biggest problem of the time — the lack of a unified approach to implementing standards. Yes, I'm looking at you, Internet Explorer, and your ActiveX.&lt;/p&gt;

&lt;p&gt;As a result, each browser had its own tools for working with HTML, meaning simple scripts for animating snowflakes might not work in a competitor's browser if you only tested your code in Internet Explorer or vice versa, in Netscape Navigator. This could and did lead to unpredictable behaviour, bloated code, and logical errors.&lt;/p&gt;

&lt;p&gt;In 1994, the World Wide Web Consortium (W3C) was established to standardize web technologies and make life easier for web developers. One of the key initiatives of this organization was the creation of the DOM, or Document Object Model, to standardize interactions with web documents.&lt;/p&gt;

&lt;p&gt;The first version of the DOM documentation was published in 1998, marking a significant milestone in web development history. Finally, a standardized way of representing and interacting with HTML documents was introduced, allowing developers to hope their snowflakes would fall the same way in all relevant browsers. The first DOM became the foundation for modern web applications.&lt;/p&gt;

&lt;p&gt;However, this didn't mean all web development problems were solved that year. Rather, they reached a new level. Now, besides incompatibility with competitors, most browsers became incompatible with the standard. Some tried to fix this, some ignored it, and some pretended that the most standard standards were only what they did, while other standards were not so standard. The fact that the famous jQuery emerged only in 2006 vividly indicates that the cross-browser compatibility issue not only didn't disappear but flourished eight years after the DOM standard appeared.&lt;/p&gt;

&lt;p&gt;But that's a story for another time.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>html</category>
      <category>development</category>
      <category>history</category>
    </item>
    <item>
      <title>What is, in fact, HTML and do we still need it in 2024?</title>
      <dc:creator>Serhii Babich</dc:creator>
      <pubDate>Fri, 10 May 2024 05:39:16 +0000</pubDate>
      <link>https://dev.to/babichweb/what-is-html-actually-and-do-we-still-need-it-in-2024-35pi</link>
      <guid>https://dev.to/babichweb/what-is-html-actually-and-do-we-still-need-it-in-2024-35pi</guid>
      <description>&lt;p&gt;The year 1989 was an interesting time. While the Berlin Wall was being dismantled in Germany and Nintendo Game Boy started conquering the world, my beloved Ukraine experienced the first truly Ukrainian music festival "Chervona Ruta", and the "Braty Hadyukiny" released their debut album &lt;a href="https://open.spotify.com/album/7AFWovaaWclERrRwddyHvk"&gt;"Vs'o Chotko"&lt;/a&gt;, forever changing the songs Ukrainian youth would sing around campfires in the mid-2000s.&lt;/p&gt;

&lt;p&gt;Around the same time, a CERN employee named Tim Berners-Lee proposed the idea of a system of interconnected hypertext documents, laying the foundation for what would later become the World Wide Web, giving us all jobs and the ability to access all of humanity's knowledge, as well as pictures of naked bottoms, within a moment's reach.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frkx1clt9bn4ip3nn6s02.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frkx1clt9bn4ip3nn6s02.jpeg" alt="Mr. Berners-Lee looks at you when you say you don't want to learn HTML because you know React" width="800" height="420"&gt;&lt;/a&gt;&lt;/p&gt;
Mr. Berners-Lee looks at you when you say you don't want to learn HTML&lt;br&gt;because you know React



&lt;p&gt;To bring this idea to life, Mr. Berners-Lee began working on a revolutionary language - HTML, or Hypertext Markup Language. In 1991, he published a publicly accessible document that described this language, which included all 18 HTML tags that existed at the time, many of which are still part of the HTML specification today.&lt;/p&gt;

&lt;p&gt;By the way, did you know that the world's first web page still exists and can be visited at &lt;a href="https://info.cern.ch"&gt;this link&lt;/a&gt;? Actually, it's a copy, because the original page was hosted on Tim's own NeXT computer, and to keep access uninterrupted, there was a note on the system unit that said &lt;strong&gt;DO NOT TURN OFF&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;So what exactly is HTML? It's a markup language. But what do we mark up? And what is markup in principle? The answer, though obvious, is not too simple, so let's try to figure it out.&lt;/p&gt;

&lt;p&gt;It is important to remember that HTML was primarily developed for marking up documents. A document differs from simple text in that it serves, so to speak, as a structured container for various information, including text, images, tables, lists, and other types of data compilation. The main purpose of documents is to organize all this data in such a way that it all makes some sense.&lt;/p&gt;

&lt;p&gt;And thus, to be able to create documents, there exists markup, which allows separating certain parts of the document from each other and indicating the specific role and meaning of these parts. We can explicitly indicate that this is a headline, this is a section, here's a table, there's a link, and this is a picture of a cat. And in order for the system that processes the document to have some idea of what we want from it, we must have at least two things: a clear set of instructions that we use for such markup, and a dictionary of these instructions, so that the system understands the meanings of these instructions just as we do.&lt;/p&gt;

&lt;p&gt;And HTML is exactly that set of instructions (for those who might be interested, this language is based on &lt;a href="https://en.wikipedia.org/wiki/Standard_Generalized_Markup_Language"&gt;SGML&lt;/a&gt;). And the specification is that dictionary. We can explicitly tell the browser which version of the specification to use for a particular document, and depending on that, the display result can vary significantly.&lt;/p&gt;

&lt;p&gt;In general, document markup can perform a lot of tasks. We've already learned a bit earlier about dividing content by role and meaning, but there are other tasks that the same HTML tags can perform. For example, formatting. That is, we can specify not only &lt;strong&gt;what&lt;/strong&gt; to display, but also &lt;strong&gt;how&lt;/strong&gt;, relying either on built-in styles or on our own.&lt;/p&gt;

&lt;p&gt;Also, for example, you can store and transmit certain data. This is more related to XML, but in HTML you can do this using attributes. In this way, you can even store some initial or intermediate state that can affect the display of an element.&lt;/p&gt;

&lt;p&gt;Also, proper markup is an important part of &lt;strong&gt;accessibility&lt;/strong&gt; — a set of web content development practices that allow users with disabilities to use the web conveniently and effectively. This includes not only visual impairments but also mobility and even cognitive disorders.&lt;/p&gt;

&lt;p&gt;And, of course, it allows for an absolute separation of content from presentation. For example, using HTML together with CSS, we can completely change the appearance of the entire document or its parts, without changing the structure of the document itself.&lt;/p&gt;

&lt;p&gt;The best illustration of this is &lt;a href="https://csszengarden.com/pages/alldesigns"&gt;CSS ZEN GARDEN&lt;/a&gt; — a site that has thousands of faces. Its HTML has not changed since 2003, but during this time it has changed many styles, becoming a kind of challenge for developers who create new, completely different designs using the same markup.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2xayhxboi3ew7nnsim9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fm2xayhxboi3ew7nnsim9.jpg" alt="Image description" width="800" height="600"&gt;&lt;/a&gt;&lt;/p&gt;
Few or the thousand faces of CSS ZEN GARDEN



&lt;p&gt;Well, well, you might say, we understand what it is, and even what it's for. But where can it be used, this HTML? The first thing that comes to mind, of course, is for developing web pages. But it would be very wrong to assume that its practical application ends there. On the contrary, it's just beginning.&lt;/p&gt;

&lt;p&gt;After all, remember that HTML is a hypertext markup language, that is, designed for marking up hypertext documents. It doesn't say it has to be only web documents. Well, not just web documents.&lt;/p&gt;

&lt;p&gt;One such case is email. Usually, we use very simple means to format our text, but most email clients understand more complex markup, although if you want to create all sorts of sophisticated layouts, I have bad news for you — you'll have to forget about the benefits of modern CSS and turn to the forbidden dark arts of table formatting.&lt;/p&gt;

&lt;p&gt;You can say, of course, that HTML can also be used for desktop development, but this is very, very relative, because, in fact, it's the same browser with certain perks and custom icons.&lt;/p&gt;

&lt;p&gt;If we talk about really non-web use, then we can mention the &lt;a href="https://www.w3.org/TR/epub-33"&gt;EPUB&lt;/a&gt; format for electronic books, and indeed many different formats rely on HTML.&lt;/p&gt;

&lt;p&gt;In principle, HTML can also be used in printing, especially if you skillfully use CSS media queries, in particular &lt;code&gt;@media print&lt;/code&gt;. This, of course, requires some effort, but I assure you that you can definitely prepare a small book for printing.&lt;/p&gt;

&lt;p&gt;Let's turn away from the traditional perception of the HTML document as a document to the current state of affairs. We can see an incredibly diverse and vast realm of user interfaces, with the help of which we can do a lot of different things — click, drag, push, input, open, close, and generally interact in all sorts of ways.&lt;/p&gt;

&lt;p&gt;User interfaces can be anywhere, and the ease of launching a web browser on any kind of device contributes to the fact that HTML is spreading to an increasing number of devices. If I were to list everything into which you can fit a screen and a trimmed browser, I would probably run out of character limit for this article.&lt;/p&gt;

&lt;p&gt;So let's imagine the most obvious examples where you can meet our favourite language: smart and not-so-smart TVs, car onboard computers, interactive kiosks, self-service terminals, and other devices.&lt;/p&gt;

&lt;p&gt;And also... video games. Yup. For example, for Unreal Engine there is a Web Browser Widget plugin that allows you to create a game interface using HTML, CSS, and JS. In general, the soulless machine named ChatGPT tries to convince me that at least EVE Online, Battlefield, and Destiny 2 use HTML to display certain parts of the interface. I haven't found 100% confirmation of this information, but various hints scattered across the internet also indicate that web technologies find their place even in the development of AAA games.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvplyrywarnnrg7uoophy.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/cdn-cgi/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fvplyrywarnnrg7uoophy.png" alt="Image description" width="800" height="453"&gt;&lt;/a&gt;&lt;/p&gt;
evevision — UI extension for EVE online built with HTML, CSS and JS



&lt;p&gt;In general, HTML remains a constantly evolving living language, not only gaining new capabilities but also getting rid of frankly outdated and unnecessary tags. For example, &lt;code&gt;center&lt;/code&gt; and &lt;code&gt;font&lt;/code&gt; have sunk into oblivion thanks to CSS, &lt;code&gt;menu&lt;/code&gt; and &lt;code&gt;dir&lt;/code&gt; have been replaced by the more general &lt;code&gt;ul&lt;/code&gt;, and tags like &lt;code&gt;nextid&lt;/code&gt; would have made rise a brow even at their time.&lt;/p&gt;

&lt;p&gt;On the other hand, modern HTML is enriched not only with new semantic elements but also quite functional ones, for example, &lt;code&gt;dialog&lt;/code&gt; for displaying dialog windows. Or finally, support for elements that have been in the standard since 2014 but have just now been implemented by browsers. Well, you know, like finally cleaning up your shed.&lt;/p&gt;

&lt;p&gt;Today, there is no way around web development without HTML, and tomorrow — who knows where else this language will become the standard. To some, it seems overly simple, to others — clunky, to some primitive, to others — too complicated. But that does not negate the fact that HTML is the foundation of web development, and without it, we would have nothing to decorate with CSS or animate with JS.&lt;/p&gt;

&lt;p&gt;Can you not learn HTML in today's world full of frameworks? You definitely can. Should you learn HTML in today's world full of frameworks?&lt;/p&gt;

&lt;p&gt;You definitely should.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Please, strike a comment, either you liked or disliked this article and let me know if you'd like to read such texts on other topics. I would greatly appreciate your feedback!&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Thank you and have a nice day!&lt;/em&gt;&lt;/p&gt;

</description>
      <category>beginners</category>
      <category>html</category>
      <category>webdev</category>
      <category>discuss</category>
    </item>
    <item>
      <title>Accordion Tabs with pure CSS</title>
      <dc:creator>Serhii Babich</dc:creator>
      <pubDate>Wed, 23 Jun 2021 14:31:52 +0000</pubDate>
      <link>https://dev.to/babichweb/accordion-tabs-with-pure-css-35ji</link>
      <guid>https://dev.to/babichweb/accordion-tabs-with-pure-css-35ji</guid>
      <description>&lt;p&gt;Yep, this is yet another “article” about how amazing pure CSS is, and how you can do something cool without a single line of JavaScript. Why do I bother to write it? Because I am still fascinated by how amazing pure CSS is, and how you can do something cool without a single line of JavaScript.&lt;/p&gt;

&lt;p&gt;Before we start — you can find demo of this code hosted &lt;a href="https://sergiybabich.github.io/html-accordion-tabs/"&gt;here&lt;/a&gt; and the code itself hosted &lt;a href="https://github.com/sergiybabich/html-accordion-tabs"&gt;here&lt;/a&gt;. Feel free to explore and play around!&lt;/p&gt;

&lt;p&gt;&lt;small&gt;The final tiny disclaimer: all this is just for fun and to show you how amazing CSS is.&lt;/small&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  HTML structure
&lt;/h2&gt;

&lt;p&gt;We will use very simple HTML markup to define our accordion tabs:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;.tabs-container&lt;/code&gt; — wrapper element to host all tab related elements;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;input.tab-actor&lt;/code&gt; — hidden radio-button to control tab content visibility;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;label.tab-button&lt;/code&gt; — label linked to input, serving as tab button;&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;.tab-content&lt;/code&gt; — wrapper for any content you’ll feel worth putting into;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The tiniest example ever will look like this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-container"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"tab-1"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"tabs"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-actor"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"tab-1"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;section&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"content"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;…&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/section&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  How this works
&lt;/h2&gt;

&lt;p&gt;The main idea is to use a very simple yet powerful ability of HTML form controls to have a state and the ability to access this state with CSS pseudo-classes. Namely, I use &lt;code&gt;:checked&lt;/code&gt; pseudo-class here. This means I style adjacent siblings of the checked input using &lt;code&gt;+&lt;/code&gt; combinator.&lt;/p&gt;

&lt;p&gt;To emulate tabs behaviour, I need to display only active tab content. By active I mean the closest adjacent to the checked radio.&lt;/p&gt;

&lt;p&gt;The radio-button also should be hidden, leaving only the linked label visible and interactive.&lt;/p&gt;

&lt;p&gt;Long story short, this is how these tabs are intended to work. Let’s write some basic CSS code for the tabs.&lt;/p&gt;

&lt;h2&gt;
  
  
  Some basic code
&lt;/h2&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nd"&gt;:root&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="py"&gt;--tab-button-order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;--tab-content-order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;10&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-actor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--tab-button-order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--tab-content-order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s go through each rule to understand what happens.&lt;/p&gt;

&lt;p&gt;First, I create some CSS variables for an order property, and this is what the inside &lt;code&gt;:root&lt;/code&gt; rule is. We’ll get back to this a bit later.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-wrap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;wrap&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We employ flex layout. It allows us to use an unknown number of tabs because it automatically distributes its children. Otherwise, we need to put the fixed-width values manually.&lt;/p&gt;

&lt;p&gt;By default, all flex items are cramped in one line, but we need the tab buttons placed at the top and content at the bottom. Using &lt;code&gt;flex-wrap: wrap&lt;/code&gt; allows flex layout to put large elements to the next row.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;input&lt;/span&gt; &lt;span class="na"&gt;type=&lt;/span&gt;&lt;span class="s"&gt;"radio"&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"tab-1"&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"tabs"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-actor"&lt;/span&gt; &lt;span class="na"&gt;checked&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;label&lt;/span&gt; &lt;span class="na"&gt;for=&lt;/span&gt;&lt;span class="s"&gt;"tab-1"&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"tab-button"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;Lorem ipsum&lt;span class="nt"&gt;&amp;lt;/label&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We link label to input using &lt;code&gt;id&lt;/code&gt; attribute for the input and for attribute for the label. When the input-label pair has the same values of the attributes, clicking the label activates the input as we click directly on the input.&lt;/p&gt;

&lt;p&gt;This allows us to hide input:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-actor&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Next, we add some black flex magic to get the layout we want.&lt;/p&gt;

&lt;p&gt;HTML we have already written results in this:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tab]
[content]
[tab]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But what we need is the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;[tab][tab]
[content]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;To achieve our goal we should use an &lt;code&gt;order&lt;/code&gt; CSS property that orders (no pun intended) elements inside flex layout despite the actual position in the DOM-tree. The following code sets the order for &lt;code&gt;.tab-button&lt;/code&gt; elements to be at the start of layout and &lt;code&gt;.tab-content&lt;/code&gt; to be at:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--tab-button-order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--tab-content-order&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;code&gt;.tab-content&lt;/code&gt; is hidden by default. We unhide active tab content using the code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It’s a big selector, for sure, but it does all the magic. All content is hidden, and we want to display only the content corresponding to the activated tab button. This selector literally says the following:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Display the content after the button that follows the checked input&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;+&lt;/code&gt; combinator selects immediately adjacent elements, that’s why the HTML code should follow this exact order.&lt;/p&gt;

&lt;p&gt;Another approach is to use &lt;code&gt;~&lt;/code&gt; combinator. It is also adjacent but not strict and selects &lt;strong&gt;all&lt;/strong&gt; matching adjacent elements. Using &lt;code&gt;~&lt;/code&gt; shortens the selector to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Though in this case, the first tab activates all adjacent content. To avoid this, we need to specify which tab displays which content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="c"&gt;/* Don't write code like this. Please. */&lt;/span&gt;
&lt;span class="nc"&gt;.tab-actor.tab-1&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.tab-content.tab-1&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.tab-actor.tab-2&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.tab-content.tab-2&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.tab-actor.tab-3&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.tab-content.tab-3&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
&lt;span class="nc"&gt;.tab-actor.tab-4&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;~&lt;/span&gt; &lt;span class="nc"&gt;.tab-content.tab-4&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Not that much optimization, to be honest.&lt;/p&gt;

&lt;p&gt;Ok, now we have not that pretty but working tabs made with pure CSS and HTML.&lt;/p&gt;

&lt;h2&gt;
  
  
  Music time!
&lt;/h2&gt;

&lt;p&gt;Or, to be precise, it’s time to convert tabs into the accordion.&lt;br&gt;
Why?&lt;/p&gt;

&lt;p&gt;On small screens, tabs aren’t the best option to display content, and the very layout we tried to avoid at the beginning comes in handy here:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Desktop:
[tab][tab]
[content]

Mobile:
[tab]
[tab]
[content]
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;All we need is just to revert flex order and adjust the button width to small screens:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;480px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.tab-button&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt;
  &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;order&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;initial&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100%&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;That’s it. It works.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wait! There is more!
&lt;/h2&gt;

&lt;p&gt;It’s all cool and great, but these tabs are so booooring. Let’s glam them up!&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;margin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nt"&gt;body&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;font-family&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;Arial&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;"Helvetica Neue"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;Helvetica&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nb"&gt;sans-serif&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1280px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;margin-inline&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-container&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;box-shadow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;rgba&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;0.5&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="m"&gt;2px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;justify-content&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;center&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;8px&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;border-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;transparent&lt;/span&gt; &lt;span class="m"&gt;4px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;border-bottom-color&lt;/span&gt; &lt;span class="m"&gt;0.4s&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;padding&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;16px&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;border-bottom-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;rgb&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;82&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="m"&gt;136&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We add some paddings, colours and a bit of animation. Looks great now! Though, as you can notice, content in the “mobile” mode switches dully, without a single spark of joy. Let’s add some sparks then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@media&lt;/span&gt; &lt;span class="n"&gt;screen&lt;/span&gt; &lt;span class="n"&gt;and&lt;/span&gt; &lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;max-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;480px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;border-bottom&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1px&lt;/span&gt; &lt;span class="nb"&gt;solid&lt;/span&gt; &lt;span class="m"&gt;#ccc&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;background-color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;ivory&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300ms&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;

  &lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;What happens here? We add a &lt;code&gt;.full-height&lt;/code&gt; class to our &lt;code&gt;.tab-container&lt;/code&gt; and sprinkled some fun CSS over it.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;100vh&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex-direction&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;column&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right here we tell our accordion to occupy exactly the full-screen height and order all children in column flex layout.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;display&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;block&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;auto&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;0&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;overflow&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;hidden&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nl"&gt;transition&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;300ms&lt;/span&gt; &lt;span class="n"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;

&lt;span class="nc"&gt;.tab-container.full-height&lt;/span&gt; &lt;span class="nc"&gt;.tab-actor&lt;/span&gt;&lt;span class="nd"&gt;:checked&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-button&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nc"&gt;.tab-content&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;flex&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we cast some magic on &lt;code&gt;.tab-content&lt;/code&gt;, allowing it to expand and collapse with a neat animation.&lt;/p&gt;

&lt;h2&gt;
  
  
  Epilogue
&lt;/h2&gt;

&lt;p&gt;That’s, my friends, is how I met… Ah, sorry, it is how we can make responsive tabs that switch to the accordion layout on the fly without a single line of JS.&lt;/p&gt;




&lt;p&gt;Edited by &lt;a href="https://twitter.com/Ulyanka_A"&gt;@Ulyanka_A&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>html</category>
      <category>tutorial</category>
      <category>beginners</category>
    </item>
  </channel>
</rss>
