Welcome to the second installation in my series teachingΒ HTML & CSS for Bloggers. The first post sharedΒ basics that help with SEO. In this post, weβll go over CSS basics for a beautiful blog.
What is CSS?
Β
Iβm glad you asked! But letβs start by definingΒ HTML.
HTML stands for βHypertext Markup Language.β HTML defines the basic structure for a website. It tells the browser what to put in your header, the main body, and the footer. The HTML document should contain all text and call outs to Javascript (like your Google Analytics code, for example) and CSS. Basically, an HTML document pulls each part of the website together even if it doesnβt store all the specific code details.
CSSΒ stands for βCascading Style Sheetsβ. CSS determines how your page looks, both in terms of font type, color, size, and even where certain elements sit on your page. It defines the size of the header, body, footer, and really so much more than that. For the purpose of this post, weβll focus primarily on simple CSS basics for a beautiful blog and save the more advanced topics for later lessons (soΒ subscribe to the newsletter in the sidebarΒ if you want to keep learning more!)
How to Use CSS
Letβs assume that youβre not using WordPress and have to do everything yourself. Youβd have to manually call out the CSS file in your HTML file. It would look something like this:
The βlinkβ part of this tag is just telling the HTML document that youβre calling another file in to be displayed on the page. The βrelβ tells the document exactly what youβre calling, which in this case is stylesheet. TheΒ typeΒ is just another reference to this, but also lets the browser know it doesnβt have to do anything extra special to process the code. It doesnβt have to compile like PHP code (a more involved process) β it can just be read as-is. The βhrefβ is the source of the file and should correspond to wherever the CSS code is housed. Usually this is in itβs own specific folder, so the file path might instead read βcss/style.css.β
How to Find a WordPress CSS Stylesheet
Luckily for you WordPress users, you donβt have to set this up yourself. You can access the stylesheet connected to your active them by going toΒ Appearance > Editor > Styles > styles.css. Some themes have more than one stylesheet, but βstyles.cssβ tends to be the main one. Plugins will also contribute their own individual stylesheets, and can be accessed by going toΒ Plugins > EditorΒ and selecting individual pluginsβ stylesheets.
Be careful to make changes to this document. Itβs a good idea to backup your WordPress site, or at least saving an exact copy of your styles.css document in case you break something. Letβs talk a little bit about the structure of objects on a CSS document.
CSS Structure
A basic CSS object looks something like this:
.fontstyles {
font-size: 16px;
}
Letβs go over each part.
β.fontstylesβΒ is what we consider to be the CSS βclass.β A class is just a name to describe what your code is supposed to do.Β In HTMLΒ & CSS, we often talk about being βsemantic.β This means creating names for CSS objects that make sense as to what theyβre supposed to actually do. You can call classes whatever you want, just donβt use spaces. CSS classesΒ areΒ case sensitive, so be careful to keep this in mind when creating and implementing code.
Instead of < and > carets, CSS uses curly brackets: { and } to show where the code starts and ends. Itβs important to note that these arenβt implemented until after the name of the CSS class.
Within the code itself are specific actions. In this example, βfont-sizeβ refers to exactly what youβd expect β changing the size of a font. After the action, make sure to insert a colon (:), and end the line with a semi colon (;). You can continue to add additional actions. Say, for example, you want to define the font color in this class, as well. That code would look like this:
.fontstyles {
font-size: 16px;
font-color: green;
}
The final piece is the closing curly bracket: }
Congrats! Youβve created your first CSS style.
CSS Classes and IDs
.fontstyles {
}
A CSS ID looks something like this:
#fontstyles {
}
The only obvious visual difference here is that a class in preceded byΒ a period (.) and an ID is preceded by a hashtag symbol (#).
AΒ classΒ can be used multiple times on a page. Say you want to make specific text green, as well as a heading tag, and a link. You can insert the CSS class to achieve this.
AnΒ IDΒ can only be used once on a page. Youβd likely use an ID to define the different layout specifics. So, a footer would have itβs own ID, your sidebar would have itβs own ID, etc.
Understanding the difference between a CSS class and a CSS ID is important in CSS basics for a beautiful blog. Calling to a CSS style on HTML
As long as your HTML page links to the CSS document youβve been working on, itβs easy to call and use CSS styles on the HTML page. Referring back to the CSS style weβve been working on, letβs see how weβd apply it to a h1 tag:
< h1 class="fontstyles">HEADING TEXT HERE
Just replace the period from your CSS class with the word βclassβ and an equals sign (=) with quotations surrounding the name of the class. The same process works when defining an ID, youβre just replacing the hashtag symbol (#) instead of a period. Some pages will display the CSS code directly on the HTML page like so:
< h1 style="font-size: 16px;">HEADING TEXT HERE>
Notice that instead of defining aΒ classΒ orΒ ID, youβre just telling the HTML document that you want to give the specific HTML tag a βstyle.β Punctuation is a little different, but similar enough for it to make sense. The above code is an example ofΒ inline CSS. This is considered to beΒ very bad for SEO, because it increases page load time. Thatβs whyΒ ALL of your CSS codes should be housed on a separate CSS document.Β
Final Thoughts: CSS Basics for a Beautiful Blog
Ok, I know I promised to show you CSS basics for a beautiful blog, but I want this lesson to sink in before we talk about how to more specifically customize the look and feel of your blog theme. I promise that digging into specific styles and how to achieve them will be the very next topic! On that note, if thereβs some specific look youβre trying to achieve, leave your questions in the comments.
I probably should, huh? Anything in particular that you’d like for me to dig into more deeply?
Can you provide some more content like this?
So glad it was useful to you, Rishabh!
Amazing content. Thanks
Francesa,
So glad this could help you! Unfortunately, this is just one of two or so posts on the topic here, but I also write about web dev stuff at DeveloperDrive.com and wpmudev.org π
This is great! I had some problems applying classnames but this helped me.
(What also helped me if this is something others struggle with too: a friend of mine who worked at Facebook showed me this table: https://meiert.com/en/indices/css-properties/ –before that I didn’t even know what I could do with my html code :-/)
Have you written more about CSS lately? It seems most was about SEO and marketing or am I missing something?
Phoeicia,
I try to! Still lots for me to learn, too π
And those were the days, weren’t they? So many conflicts between themes and plugins! That could be a whole series of topics on it’s own… π
Maddy
Wow – you truly know your stuff!
Thank goodness for WordPress and website designers!
Whilst at university in the late 1990’s, we were taught how to create simple websites using html. Once the formula was correct, the page would do exactly as you instructed it – I needed no help. How far technology has come since then!
Adrienne,
I hear that from a lot of people! Web stuff isn’t easy to jump into, but I hope to make it a little more understandable!
Either a course or a book is my eventual plan. Readers like you will help keep me honest with that goal π
Thanks for stopping by!!
Maddy
Hey Maddie,
I would love to learn how to do this. I think I don’t have the patience for it because I’ve gone to the CSS Tutorial site and played around with the coding lessons but when I would try it on my blog it would never work which I found SO frustrating.
But there are some things I prefer doing myself and I continue to play around with it so for the small projects I’m all in. For the larger ones I’m out.
I do agree with Brent though, you should probably put a course together. If you did it so that we idiots could learn then you’d have an awesome customer base just from us. I’d LOVE to learn how to do this without losing my religion. LOL!!!
~Adrienne
Brent –
That’s definitely an idea I’ve toyed around with. Another is creating a book. I’m going to keep creating the content and see what would be a better fit π
And I know exactly what you mean about editing. I can get stuck in it myself too, sometimes. Even if I know what I’m doing, I’m caught between little decisions about what direction to take, stylewise!
Thanks for all your great feedback and helping me spread the word about this series π
Maddy
Maddy,
I really think you should put together a course on CSS basics. (Aimed right at total beginners)
You wouldn’t believe how many times I’ve gone to edit something small — something you could probably edit within a matter of minutes — but I end up spending 3 1/2 hours searching for the answer.
The answers I find online to what I’m trying to do with CSS are generally…
a) Far too complicated / beyond my skill level
b) Entirely incomplete
I know to someone who is “fluent” in CSS, it’s probably hard to imagine that it could be challenging to other people.
But I’ll be the first to admit that I could use help.
Just an idea.
Brent
Appreciate the kind words, Cailyn! I’ll try to be updating these with new topics on a weekly basis π
You are awesome at explaining things for a newbie! Thanks SO much – definitely just bookmarked this!
Olga – You’ll get there! Thanks for stopping by π
Ahhh this is all like a different language to me, but you explain it all so well!! Thank you!
Xo,
Kristi
http://www.522envy.com
Glad you liked it! Stay tuned for more deep-digging articles π
Thanks for the explanation. I use WordPress and it takes time and practice to master it (I AM Not Even close) π
Super helpful! I’m new to the blogging world! thanks π