Source code for Half Naked Literacy

<!DOCTYPE html> <!-- (That first line above is called a DOCTYPE and it's a special instruction to the browser about what kind of document this is. It's not important for us right now, so don't worry about it.) Hey, hi there! My name is Al Abut and I created this page to demystify HTML and CSS, which is the text you're reading right now. It's also the code that creates the web page that you see in a browser window. It's both! If you've never "viewed source" in your browser before, welcome! I hope this is the first of many times you peek behind the curtain and see how the web is created. It may not always be as easy to read as this page but that's ok too, because it'll get easier the more you do it and you have to start somewhere. Let me take a minute to explain what viewing source means when it comes to web pages. Everything else on this page will make a lot more sense after a quick crash course on the basics. Viewing source is a way to see the HTML and CSS code that makes up the page you're looking at. It's a great way to learn how websites work and how to create your own. If you're on desktop, you can look for "view source" in your browser menu bar. That will show you the code that you're looking at right ow. If you're on a mobile device, there's really no easy way to view the source code, so if you're reading this on mobile, then this version you're looking at is a special version I made for you. It's like a simulation of what you might get on desktop. But that's ok! Because the whole point of this page is to make something that's easy to read at your own pace and on your own time, so it's always there and waiting for when you're ready to look at it on a laptop or desktop computer some other time. Ok, so that's how to view the source of a web page! You'll see the code that makes it look totally different in a browser, like seeing the underlying skeleton. And most of that skeleton is called HTML, which stands for HyperText Markup Language. That also sounds like gobbledygook at first but it breaks down into two simple terms: * HyperText just means that you can make links to other pages. * Markup Language just means that you use special tags to mark up the text, like making it bold or italic or adding links to other pages. That's it, that's HTML in a nutshell. The rest is just details, mainly about making it look good. The first thing to learn about HTML is comments. That's what this whole section you've been reading so far is called - comments. Comments in HTML are like documentation - a way to write notes to yourself or other programmers about the code you're writing. They're not visible to you or any other visitors to the web page, they're tucked away here in the code, like invisible secret notes to yourself or other curious visitors. Writing lots of comments is a good practice for any kind of programming and not just for web pages. It's a great way to explain your code to future versions of yourself, like you're capturing your thoughts as you go along so it'll make it easier to understand later on. You might not usually write as much as I'm writing here, but on the other hand sometimes you do if you're working on a complex project. It all depends. That's because comments aren't always just for you, they can also be a really helpful way to explain your work to others, like I'm doing right here to you, dear reader! The way you let a browser know that something is a hidden comment and that it shouldn't show up on the web page is by using these special characters to start, in exactly this sequence: < a left angle bracket ! an exclamation mark - a hyphen - a hyphen And that's it. I can't actually type it here because then the browser would get confused! Don't worry, you'll see a lot of that coming up in the code below and you'll get the hang of it quickly. Then you let the browser know that the comment is over by using these special characters to end, in exactly this sequence: - a hyphen - a hyphen - > a right angle bracket It's like casting a magic spell right before and after your writing to make it invisible to the browser, turning it into our little secret between humans. So with that, I'm going to bow out and end this little comment section with exactly those sequence of characters I described and get on with explaining the rest of the page... --> <html lang="en"> <!-- Hey, it's me again! See? That was easy. Here's another comment that started with the same special characters and is going to end with another sequence. Now that comments are out of the way, let's explain the <html> tag between these two comments. What are tags? I'm glad you asked. Tags are pairs of special words that start with a < and end with a >. They're like little containers that wrap around words and to tell the browser what to do with the other words inside them. Some might make text bold, others might create a link. There's a whole bunch and you don't have to know them all, we're going to cover some of the most common ones here on this page. So the first tag we're going to cover is the <html> tag. The part you just saw is the opening tag, which is the <html> part. The second part is way down at the very bottom of the page, which is the </html> part. And that's the format all tags follow. You surround the opening tag with the angle brackets < and > and then the closing tag is the same thing but with a / in front of it. So it all looks like this: <WORD>...</WORD> <FOO>...</FOO> <BAR>...</BAR> You get the idea. --> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1, minimal-ui"> <title>Simple Page</title> <!-- Plausible is a privacy-focused analytics tool that doesn't require cookies or GDPR notice. --> <script defer data-domain="alabut.com" src="https://plausible.io/js/script.outbound-links.js"></script> <!-- Webmentions are a way to let me know if you write a response to my writing with a like, comment or article. --> <link rel="webmention" href="https://webmention.io/alabut.com/webmention" /> <style> /* Define CSS variables at the root level to be used throughout the document. */ :root { /* Ok, first let's define some colors to use throughout the page. */ /* Dark background for the page */ --background-color: #0B0C0C; /* Light text color for readability */ --text-color: #f0f0f0; /* Default link color */ --link-color: #FF8600; /* Link color on hover and focus */ --link-hover-color: #fff; /* Link color when clicked */ --link-active-color: #f0f0f0; /* Wondering where these colors came from? More info on this color theme: - Uses this palette: https://coolors.co/palette/8ecae6-219ebc-023047-ffb703-fb8500 - Checked contrast with this tool: https://webaim.org/resources/contrastchecker/ - The contrast of the links still need work, according to Google's Pagespeed/Lighthouse tool. Although the links have enough pop compared to the background, they're not differentiated enough from the surrounding white body text. */ /* Useful Resources for Colors and Fonts: - Color Pickers: Visit https://coolors.co for generating color schemes or https://colorhunt.co for color palette inspiration. - Fonts: Explore https://fonts.google.com for a wide range of free fonts and easy integration into your web projects. Note that we're not using any web fonts here, just system fonts. - System Fonts: For faster load times and simplicity, consider using system fonts such as Arial, Georgia, or 'Courier New'. These fonts do not require any downloads or external resources. Learn more about using system fonts in CSS here: https://css-tricks.com/snippets/css/system-font-stack/ - These resources help you choose visually appealing colors and fonts to enhance the aesthetics of your web pages. */ /* Chooses a universal font family for web use. Universal in two senses of the word - meant to be used throughout the page itself, as well as the using stock system fonts that are universally available to browsing devices, rather than loading from an external resource like Google Fonts. */ --font-family: Helvetica, Arial, sans-serif; /* Set the font size for readability. Using px is fine, browsers can resize as needed. There's no need for overthinking it with more complicated relative units and ratios that accidentally create weird edge cases when cascading into nested blocks of text. */ --font-size: 18px; /* Finally, let's set the spacing between the lines of text so it's not too cramped. */ --line-height: 1.5; } body { /* Typography & Theming */ background-color: var(--background-color); color: var(--text-color); font-size: var(--font-size); font-family: var(--font-family); line-height: var(--line-height); /* Layout */ /* Add space around the content inside the body tag. */ padding: 20px; /* Set the maximum width of all content within the body. Using 'ch' units, where 1ch is approximately the width of the '0' character. Optimal line lengths are between 45 to 75 characters wide, with 66 the ideal. It's set to 55 here because that resulted in 66 characters wide with typical writing (i.e. not a repeating sequence of zeroes) */ max-width: 55ch; /* Centers the content horizontally on the page. */ margin: auto; } /* Theming */ a { color: var(--link-color); text-decoration: none; } a:hover, a:focus { color: var(--link-hover-color); text-decoration: underline; } a:active { color: var(--link-active-color); } /* Blockquote styling with border outside margin */ blockquote { border-left: 4px solid var(--link-color); margin-left: 0; padding-left: 10px; position: relative; } .inverse { background-color: var(--link-color); border-radius: 20px; color: var(--background-color); font-size: 1.2em; font-weight: bold; margin: 20px 0; padding: 10px 20px; } </style> </head> <body> <h1>Half Naked Literacy</h1> <p> Welcome to this very basic example of a web page. It has two main goals: </p> <ol> <li> To bring the concept of <a href="https://en.wikipedia.org/wiki/Literate_programming">literate programming</a> to HTML so that the markup itself is the documentation for the project. </li> <li> To be the "half naked" version of <a href="https://css-naked-day.org">CSS Naked Day</a>, with a modicum of styling to make it readable. </li> </ol> <h2>Goal 1: Literate HTML</h2> <p> Let's start with the formal definition of literate programming: </p> <blockquote> <p> <em>&ldquo; Literate programming is when the programmer writes the documentation for the code in the same file as the code itself. This is in contrast to traditional programming, where the documentation is written in a separate file. &rdquo;</em> </p> </blockquote> <p> In plain English, it means you write the code and the help text that explains it all in the same document, so you don't have to switch between multiple files to understand what's going on. </p> <p> For an HTML page like this one, that documentation is in the form of a bunch of comments in the HTML that explains how it works. If you're on a laptop or desktop computer, you can use the "view source" feature of your browser to see these comments that I've sprinkled throughout the markup. </p> <p> If you're on mobile instead then don't sweat it, I made <a href="/projects/halfnaked/viewsource.html">this special version of the page</a> that simulates what you'd see elsewhere. </p> <p> I wrote <em>a metric ton</em> of comments in the HTML of this page. Almost a crazy amount, to be frank, like I was writing a novel about the adventures of Mr Markup and Mrs Browser. The goal of writing so much was to make everything self-explanatory, even if you've never seen the source of a web page before. </p> <h2>Goal 2: Half Naked CSS</h2> <p> This page also exists as a small demonstration of why I can never fully participate in CSS Naked Day, a fun annual event where people strip away the CSS from their websites for a day to celebrate the beauty of plain text and unstyled HTML. </p> <p> That might sound surprising if you read the section above, and really surprising if you cracked open the source of this page and saw all the comments explaining every single element. Clearly I love HTML. </p> <p> I'm exactly the kind of person who should love this. I might be old but hey, I like fun. I've been using HTML since before CSS had layouts. I love the minimalism and simplicity of clean markup for a host of reasons. It easier to write, read, and maintain; it performs like a champ on slow connections and fast alike. </p> <p> Most of all, it's appealingly punk rock to strip things down to the core fundamentals and go against the grain in an era of vibe coded junk output. </p> <p> However, as much as I appreciate the ideals behind going "naked" once a year, there's one big massive catch for me: I personally find plain text and unstyled HTML to be nearly unreadable on desktop. </p> <p> Font sizes, line lengths, and spacing all default to settings that haven't worked since the pre-tables era of the early web. The black text on white not only starches your eyes if you're reading in the evening, but it looks like an accidental kind of broken, rather than something that's clearly intentionally simple. </p> <p> It looks undesigned. Even your average code editor looks better in comparison. Why strip away the style if that's the result? </p> <p> I mean come on, demonize javascript all you want. But CSS? Stylesheets are the shit. </p> <p> The good news? You don't actually need a lot of CSS to fix this! With just a few lines, you can make an immense improvement in legibility and drag the page into the modern era. <strong>Minimal effort, maximum benefit.</strong> </p> <p> Enough rambling. If just looking at this page hasn't convinced you yet, let's unpack the details of the formatting tweaks. </p> <h3>Formatting Details</h3> <h4>Line Length</h4> <p> There's only so long a line of text can be before it becomes difficult to read. The ideal length is between 45 to 75 characters wide, with 66 the ideal. It's set to 55 here because that resulted in 66 characters wide with typical writing (i.e. not a repeating sequence of zeroes) </p> <h4>Centered Content</h4> <p> The best thing the iPhone ever did was to kill the trend of sidebars and annoying distractions that dominated the web in the early 2000s. Out went old timey newspaper-style layouts and in came a focused experience around a single column of text. Give your words room to breathe. </p> <h4>Typography</h4> <p> Font size, font family, and line height. The basic currency of not just readability but also the personality behind the words. I.e. design. </p> <p> Why make your text look like it was pooped out by a machine? You're human, we're all different, pick what works for you. </p> <h4>Contrast</h4> <p> No, not that kind of contrast like between light and dark colors. I'm talking about breaking up a column of text with the occasional blockquote, image, or other visual element. </p> <blockquote class="inverse"> <p> &ldquo;It&rsquo;s the contrast of light and dark that each give the other one meaning.&rdquo; </p> <p> <small><em>&mdash; Bob Ross</em></small> </p> </blockquote> <p> Even on a page where the text is the main course, it's good to mix things up a bit and change the rhythm. Otherwise it just becomes a never-ending stream of text with no visual breaks. </p> <h4>Dark Mode</h4> <p> I love dark mode. I love it the way Jerry Seineld loves cereal: I can enjoy it 24/7, no matter the social conventions. </p> <p> You don't need to have complicated media queries or create a javascript toggle to make it work. For a simple enough page like this one, you can just set it to dark mode by default. Boom, done. No more unexpected flashlight in the face like you're being interrogated by cops. </p> <p> Also, a design tip: pure white designs look semi-broken from a first impression standpoint, whereas dark colors fill up a space with a subtle sense of intentionality. I should unpack that in a blog post someday, or you can join me on one of <a href="https://events.indieweb.org/tag/hwc">the weekly Homebrew Club Zooms</a> if you want more color commentary (accidental pun 🤦🏻) </p> <h2>Rant Over</h2> <p> So, those were my two goals for this page. One around markup and the other focused on styles. </p> <p> You'd be forgiven for thinking that these two goals sound like they're at odds from the way I've nitpicked the brokeness of the default settings, but they're not. They're two love letters to the letters that make up the web. One is an ode to HTML, the other to CSS. They're the peanut butter and jam of the web. </p> <p> I hope you feel the same about HTML and CSS as I do, little bits of everyday magic made possible by nothing more than plain text. This polemic was just as much for me as anyone else, a reminder to step back and appreciate the building blocks of the web that we sometimes take for granted. </p> <p> And if you made it this far and actually read everything, then wow. First of all, thank you. You're exactly my kind of good egg. Secondly, you might want to stay in touch, either by <a href="/writing/">reading my blog</a> or showing up to one of the many inspiring <a href="https://events.indieweb.org/tag/hwc">Homebrew Club zooms hosted by the IndieWeb community.</a> </p> </body> </html>