HTML preprocessors can make writing HTML more powerful or convenient. For instance, Markdown is designed to be easier to write and read for text documents and you could write a loop in Pug.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. So you don't have access to higher-up elements like the <html>
tag. If you want to add classes there that can affect the whole document, this is the place to do it.
In CodePen, whatever you write in the HTML editor is what goes within the <body>
tags in a basic HTML5 template. If you need things in the <head>
of the document, put that code here.
The resource you are linking to is using the 'http' protocol, which may not work when the browser is using https.
CSS preprocessors help make authoring CSS easier. All of them offer things like variables and mixins to provide convenient abstractions.
It's a common practice to apply CSS to a page that styles elements such that they are consistent across all browsers. We offer two of the most popular choices: normalize.css and a reset. Or, choose Neither and nothing will be applied.
To get the best cross-browser support, it is a common practice to apply vendor prefixes to CSS properties and values that require them to work. For instance -webkit-
or -moz-
.
We offer two popular choices: Autoprefixer (which processes your CSS server-side) and -prefix-free (which applies prefixes via a script, client-side).
Any URLs added here will be added as <link>
s in order, and before the CSS in the editor. You can use the CSS from another Pen by using its URL and the proper URL extension.
You can apply CSS to your Pen from any stylesheet on the web. Just put a URL to it here and we'll apply it, in the order you have them, before the CSS in the Pen itself.
You can also link to another Pen here (use the .css
URL Extension) and we'll pull the CSS from that Pen and include it. If it's using a matching preprocessor, use the appropriate URL Extension and we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
JavaScript preprocessors can help make authoring JavaScript easier and more convenient.
Babel includes JSX processing.
Any URL's added here will be added as <script>
s in order, and run before the JavaScript in the editor. You can use the URL of any other Pen and it will include the JavaScript from that Pen.
You can apply a script from anywhere on the web to your Pen. Just put a URL to it here and we'll add it, in the order you have them, before the JavaScript in the Pen itself.
If the script you link to has the file extension of a preprocessor, we'll attempt to process it before applying.
You can also link to another Pen here, and we'll pull the JavaScript from that Pen and include it. If it's using a matching preprocessor, we'll combine the code before preprocessing, so you can use the linked Pen as a true dependency.
Search for and use JavaScript packages from npm here. By selecting a package, an import
statement will be added to the top of the JavaScript editor for this package.
Using packages here is powered by Skypack, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ES6 import
usage.
All packages are different, so refer to their docs for how they work.
If you're using React / ReactDOM, make sure to turn on Babel for the JSX processing.
If active, Pens will autosave every 30 seconds after being saved once.
If enabled, the preview panel updates automatically as you code. If disabled, use the "Run" button to update.
If enabled, your code will be formatted when you actively save your Pen. Note: your code becomes un-folded during formatting.
Visit your global Editor Settings.
<body>
<nav id="navbar">
<img id="navlogo"
src="https://images.unsplash.com/photo-1567446537708-ac4aa75c9c28?ixid=MnwxMjA3fDB8MHxzZWFyY2h8NXx8bG9nb3xlbnwwfHwwfHw%3D&ixlib=rb-1.2.1&auto=format&fit=crop&w=400&q=60"
alt="">
<ul>
<li><a href="#home">Home</a></li>
<li><a href="#about">About</a></li>
<li><a href="#contact">Contact</a></li>
<li><a href="#logout">Logout</a></li>
</ul>
</nav>
<main>
<h1>My Blog</h1>
<p>This is my blog. Blah Blah Blah.</p>
<h2>Recent Posts</h2>
<div class="post">
<h2>Learn CSS Selectors</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officiis, non. A sequi
accusamus consectetur voluptatum, itaque delectus sunt perferendis molestias
dolorum
quaerat id vitae adipisci. Repellendus quia praesentium pariatur consectetur.
</p>
<span><a href="https://hashode.com">Read More on Hashnode</a></span>
<button><span>♥</span></button>
</div>
<div class="post">
<h2>Learn JavaScript Variables </h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officiis, non. A sequi
accusamus consectetur voluptatum, itaque delectus sunt perferendis molestias
dolorum
quaerat id vitae adipisci. Repellendus quia praesentium pariatur consectetur.
</p>
<span><a href="https://hashode.com">Read More on Hashnode</a></span>
<button><span>♥</span></button>
</div>
<div class="post">
<h2>Learn React and Hooks</h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officiis, non. A sequi
accusamus consectetur voluptatum, itaque delectus sunt perferendis molestias
dolorum
quaerat id vitae adipisci. Repellendus quia praesentium pariatur consectetur.
</p>
<span><a href="https://hashode.com">Read More on Hashnode</a></span>
<button><span>♥</span></button>
</div>
<div class="post">
<h2>Learn Python </h2>
<p>Lorem ipsum, dolor sit amet consectetur adipisicing elit. Officiis, non. A sequi
accusamus consectetur voluptatum, itaque delectus sunt perferendis molestias
dolorum
quaerat id vitae adipisci. Repellendus quia praesentium pariatur consectetur.
</p>
<span><a href="https://hashode.com">Read More on Hashnode</a></span>
<button><span>♥</span></button>
</div>
</main>
<footer>
<ul>
<li>Copyright something something</li>
<li>April 2021</li>
<li>
Social Links
<ul>
<li><a href="www.facebook.com">Facebook</a></li>
<li><a href="www.instagram.com">Instagram</a></li>
<li><a href="www.youtube.com">Youtube</a></li>
</ul>
</li>
</ul>
</footer>
</body>
* {
box-sizing: border-box;
}
body { /*DON'T TOUCH THESE STYLES */
width: 80%;
min-height: 100vh;
margin: auto;
padding: 20px;
border: 10px solid pink;
font-family: Arial, Helvetica, sans-serif;
}
/* Give the <main> and <nav> and <footer> elements a width of 800 pixels and center them on the page*/
main,nav,footer {
width: 800px;
margin: 0 auto;
}
/* Give the element with the ID of navlogo a width and height of 100px*/
#navlogo {
width: 100px;
height: 100px;
}
/* Give all elements with the class of "post" a white background color, a a 5px pink border, a padding of 10px all round and a margin of 10px top and bottom*/
.post {
background-color: white;
border: 5px solid pink;
padding: 10px;
margin: 10px;
}
/* Select the li elements that are inside of the element with the ID of "navbar" and make
1. them inline elements
2. give them a padding of .8rem top and bottom and 1.2rem left and right
3. a background color of dodgerblue
*/
#navbar li {
display: inline;
padding: .8rem 1.2rem;
background-color: dodgerblue;
}
/* Select the first li element that is inside of the element with the ID of "navbar" and
1. give it a background of rgb(218, 22, 185)
2. a text color of white;
3.give it font weight of 700
*/
#navbar li:first-of-type {
background-color: rgb(218, 22, 185);
text-align: center;
font-weight: 700;
}
/* Select all buttons nested inside of elements with the class of "post", and give them a 2px pink border.*/
.post button {
border: 2px solid pink;
}
/* Make all visited links teal */
a:visited {
color: teal;
}
/* Select all links with an href attribute that begins with "www" and give them a color of rgb(218, 22, 185)*/
span a[href ^="www"] {
color: rgb(218, 22, 185) !important;
}
/*
Select each h2 that is nested inside of an element with the class of "post", and add an exclamation point to the end of the h2 (using ONLY CSS)
Basically add an '!' to the end of each blog post title. Make sure the h2 that says "Recent Posts" is not included.
*/
.post h2:after {
content: '!'
}
/* Select all paragraphs that are adjacent to an h1 and make them 20px font and give them a color of dodgerblue and center them on the page. (there is only one paragraph that will be styled here) */
h1+p {
font-size: 20px;
color: dodgerblue;
text-align: center;
}
/* Make the first letter of each paragraph in each blog post
1.40px font size
2.a text color of rgb(218, 22, 185).
Make sure you are only selecting the paragraphs nested inside of elements with the class of "post". Do not select the "This is my blog. Blah Blah Blah."paragraph */
.post p::first-letter {
font-size: 40px;
font-weight: bold;
color: rgb(218, 22, 185);
}
/* Give every second blog post div (class of "post") a background color of rgba(0, 0, 0, .8) and a color of white. Make sure you are styling every EVEN numbered post. The first post should be white, the second rgba(0, 0, 0, .8), etc.*/
.post:nth-of-type(2n) {
background-color: hsla(0, 33%, 1%, 0.843);
color: white;
}
Also see: Tab Triggers