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 esm.sh, which makes packages from npm not only available on a CDN, but prepares them for native JavaScript ESM 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.
<!-- Dark Mode Switch -->
<div class="theme-switch-wrapper">
<span id="toggle-icon">
<span class="toggle-text">Light Mode</span>
<i class="fas fa-sun"></i>
</span>
<label class="theme-switch">
<input type="checkbox">
<div class="slider round"></div>
</label>
</div>
<!-- Navigation -->
<nav id="nav">
<a href="#home">HOME</a>
<a href="#about">ABOUT</a>
<a href="#projects">PROJECTS</a>
<a href="#contact">CONTACT</a>
</nav>
<!-- Home Section -->
<section id="home">
<div class="title-group">
<h1>Custom Title Here</h1>
<h2>Welcome to your website!</h2>
</div>
</section>
<!-- About Section -->
<section id="about">
<h1>Undraw Illustrations</h1>
<div class="about-container">
<div class="image-container">
<h2>Web Innovation</h2>
<div class="img-placeholder" alt="Web Innovation" id="image1"></div>
</div>
<div class="image-container">
<h2>Problem Solving</h2>
<div class="img-placeholder" alt="Problem Solving" id="image2"></div>
</div>
<div class="image-container">
<h2>High Concept</h2>
<div class="img-placeholder" alt="Conceptual Idea" id="image3"></div>
</div>
</div>
</section>
<!-- Projects Section -->
<section id="projects">
<h1>Buttons</h1>
<div class="buttons">
<button class="primary">Primary</button>
<button class="secondary">Secondary</button>
<button class="primary" disabled>Disabled</button>
<button class="outline">Outline</button>
<button class="secondary outline">Alt Outline</button>
<button class="outline" disabled>Disabled</button>
</div>
<div class="text-box" id="text-box">
<p>Lorem ipsum dolor amet consectetur adipisicing elit. Voluptatibus magnam sit alias eos ducimus expedita quam, corporis, blanditiis vel facilis, animi adipisci? Nemo enim quisquam maiores minima, qui omnis. Accusamus! Lorem ipsum dolor sit amet consectetur adipisicing elit. Dolorem magnam accusamus qui, ab voluptates reprehenderit rerum quo mollitia libero asperiores doloremque dolores, nihil repellat doloribus perspiciatis magni dolore dolorum ipsam!</p>
</div>
</section>
<!-- Contact Section -->
<section id="contact">
<div class="social-icons">
<i class="fab fa-github"></i>
<i class="fab fa-codepen"></i>
<i class="fab fa-linkedin-in"></i>
<i class="fab fa-medium"></i>
<i class="fab fa-instagram"></i>
<i class="fab fa-youtube"></i>
</div>
</section>
@import url('https://fonts.googleapis.com/css?family=Comfortaa|Kaushan+Script|Oswald&display=swap');
:root {
--primary-color: rgb(255, 92, 92);
--primary-variant: #ff2d2d;
--secondary-color: #1b9999;
--on-primary: rgb(250, 250, 250);
--on-background: rgb(66, 66, 66);
--on-background-alt: rgba(66, 66, 66, 0.7);
--background: rgb(255, 255, 255);
--box-shadow: 0 5px 20px 1px rgba(0, 0, 0, 0.5);
}
[data-theme="dark"] {
--primary-color: rgb(150, 65, 255);
--primary-variant: #6c63ff;
--secondary-color: #03dac5;
--on-primary: #000;
--on-background: rgba(255, 255, 255, 0.9);
--on-background-alt: rgba(255, 255, 255, 0.7);
--background: #121212;
}
html {
box-sizing: border-box;
scroll-behavior: smooth;
}
body {
margin: 0;
color: var(--on-background);
font-family: Comfortaa, sans-serif;
background-color: var(--background);
/* Using https://heropatterns.com/ for background */
background-image: url("data:image/svg+xml,%3Csvg width='180' height='180' viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cpath d='M81.28 88H68.413l19.298 19.298L81.28 88zm2.107 0h13.226L90 107.838 83.387 88zm15.334 0h12.866l-19.298 19.298L98.72 88zm-32.927-2.207L73.586 78h32.827l.5.5 7.294 7.293L115.414 87l-24.707 24.707-.707.707L64.586 87l1.207-1.207zm2.62.207L74 80.414 79.586 86H68.414zm16 0L90 80.414 95.586 86H84.414zm16 0L106 80.414 111.586 86h-11.172zm-8-6h11.173L98 85.586 92.414 80zM82 85.586L87.586 80H76.414L82 85.586zM17.414 0L.707 16.707 0 17.414V0h17.414zM4.28 0L0 12.838V0h4.28zm10.306 0L2.288 12.298 6.388 0h8.198zM180 17.414L162.586 0H180v17.414zM165.414 0l12.298 12.298L173.612 0h-8.198zM180 12.838L175.72 0H180v12.838zM0 163h16.413l.5.5 7.294 7.293L25.414 172l-8 8H0v-17zm0 10h6.613l-2.334 7H0v-7zm14.586 7l7-7H8.72l-2.333 7h8.2zM0 165.414L5.586 171H0v-5.586zM10.414 171L16 165.414 21.586 171H10.414zm-8-6h11.172L8 170.586 2.414 165zM180 163h-16.413l-7.794 7.793-1.207 1.207 8 8H180v-17zm-14.586 17l-7-7h12.865l2.333 7h-8.2zM180 173h-6.613l2.334 7H180v-7zm-21.586-2l5.586-5.586 5.586 5.586h-11.172zM180 165.414L174.414 171H180v-5.586zm-8 5.172l5.586-5.586h-11.172l5.586 5.586zM152.933 25.653l1.414 1.414-33.94 33.942-1.416-1.416 33.943-33.94zm1.414 127.28l-1.414 1.414-33.942-33.94 1.416-1.416 33.94 33.943zm-127.28 1.414l-1.414-1.414 33.94-33.942 1.416 1.416-33.943 33.94zm-1.414-127.28l1.414-1.414 33.942 33.94-1.416 1.416-33.94-33.943zM0 85c2.21 0 4 1.79 4 4s-1.79 4-4 4v-8zm180 0c-2.21 0-4 1.79-4 4s1.79 4 4 4v-8zM94 0c0 2.21-1.79 4-4 4s-4-1.79-4-4h8zm0 180c0-2.21-1.79-4-4-4s-4 1.79-4 4h8z' fill='%233ca5bb' fill-opacity='0.29' fill-rule='evenodd'/%3E%3C/svg%3E");
}
section {
min-height: 100vh;
display: flex;
justify-content: center;
align-items: center;
flex-direction: column;
}
h1 {
font-family: Kaushan Script, sans-serif;
font-size: 100px;
margin-bottom: 0;
}
h2 {
font-size: 32px;
font-weight: normal;
color: var(--on-background-alt);
}
/* Navigation */
nav {
z-index: 10;
position: fixed;
font-family: Oswald, sans-serif;
font-size: 24px;
letter-spacing: 3px;
padding: 25px;
width: 100vw;
background: rgb(255 255 255 / 50%);
}
a {
margin-right: 25px;
color: var(--primary-color);
text-decoration: none;
border-bottom: 3px solid transparent;
font-weight: bold;
}
a:hover,
a:focus {
color: var(--on-background);
border-bottom: 3px solid;
}
/* Home Section */
.title-group {
text-align: center;
}
/* About Section */
.about-container {
display: flex;
}
.image-container {
border: 1px solid var(--secondary-color);
border-radius: 10px;
padding: 10px 20px;
margin-right: 25px;
width: 270px;
background: var(--background);
box-shadow: var(--box-shadow);
}
img {
height: 300px;
width: 300px;
}
.img-placeholder {
height: 300px;
}
/* Projects Section */
.buttons {
margin-top: 15px;
margin-bottom: 50px;
}
button {
min-width: 100px;
height: 40px;
cursor: pointer;
border-radius: 10px;
margin-right: 10px;
border: 2px solid var(--primary-color);
font-size: 15px;
outline: none;
}
button:disabled {
opacity: 0.4;
cursor: default;
}
button:hover:not(.outline) {
filter: brightness(110%);
}
.primary {
background: var(--primary-color);
color: var(--on-primary);
}
.secondary {
border: 2px solid var(--secondary-color);
}
.secondary,
.secondary:hover,
.outline.secondary:hover {
background: var(--secondary-color);
color: var(--on-primary);
}
.outline {
background: var(--background);
color: var(--on-background);
}
.outline:hover {
background: var(--primary-color);
color: var(--on-primary);
}
.text-box {
width: 40%;
text-align: justify;
background: rgb(0 0 0 / 50%);
color: var(--on-primary);
border-radius: 10px;
padding: 30px;
}
p {
margin: 0;
line-height: 25px;
}
/* Contact Section */
.fab {
font-size: 100px;
margin-right: 50px;
cursor: pointer;
color: var(--primary-color);
}
.fab:hover {
color: var(--on-background);
}
/* Dark Mode Toggle */
.theme-switch-wrapper {
display: flex;
align-items: center;
z-index: 100;
position: fixed;
right: 25px;
top: 30px;
}
.theme-switch-wrapper span {
margin-right: 10px;
font-size: 1rem;
}
.toggle-text {
position: relative;
top: -4px;
right: 5px;
color: var(--on-background);
}
.theme-switch {
display: inline-block;
height: 34px;
position: relative;
width: 60px;
}
.theme-switch input {
display: none;
}
.slider {
background: #ccc;
bottom: 0;
cursor: pointer;
left: 0;
position: absolute;
right: 0;
top: 0;
transition: 0.4s;
}
.slider::before {
background: #fff;
bottom: 4px;
content: "";
height: 26px;
left: 4px;
position: absolute;
transition: 0.4s;
width: 26px;
}
input:checked + .slider {
background: var(--primary-color);
}
input:checked + .slider::before {
transform: translateX(26px);
}
.slider.round {
border-radius: 34px;
}
.slider.round::before {
border-radius: 50%;
}
.fas {
font-size: 30px;
margin-right: 5px;
}
const toggleSwitch = document.querySelector('input[type="checkbox"]');
const nav = document.getElementById('nav');
const toggleIcon = document.getElementById('toggle-icon');
const image1 = document.getElementById('image1');
const image2 = document.getElementById('image2');
const image3 = document.getElementById('image3');
const textBox = document.getElementById('text-box');
// Dark or Light Images
function imageMode(color) {
image1.src = `img/undraw_proud_coder_${color}.svg`;
image2.src = `img/undraw_feeling_proud_${color}.svg`;
image3.src = `img/undraw_conceptual_idea_${color}.svg`;
}
// Dark Mode Styles
function darkMode() {
nav.style.backgroundColor = 'rgb(0 0 0 / 50%)';
textBox.style.backgroundColor = 'rgb(255 255 255 / 50%)';
toggleIcon.children[0].textContent = 'Dark Mode';
toggleIcon.children[1].classList.replace('fa-sun', 'fa-moon');
imageMode('dark');
}
// Light Mode Styles
function lightMode() {
nav.style.backgroundColor = 'rgb(255 255 255 / 50%)';
textBox.style.backgroundColor = 'rgb(0 0 0 / 50%)';
toggleIcon.children[0].textContent = 'Light Mode';
toggleIcon.children[1].classList.replace('fa-moon', 'fa-sun');
imageMode('light');
}
// Switch Theme Dynamically
function switchTheme(event) {
if (event.target.checked) {
document.documentElement.setAttribute('data-theme', 'dark');
localStorage.setItem('theme', 'dark');
darkMode();
} else {
document.documentElement.setAttribute('data-theme', 'light');
localStorage.setItem('theme', 'light');
lightMode();
}
}
// Event Listener
toggleSwitch.addEventListener('change', switchTheme);
// Check Local Storage For Theme
const currentTheme = localStorage.getItem('theme');
if (currentTheme) {
document.documentElement.setAttribute('data-theme', currentTheme);
if (currentTheme === 'dark') {
toggleSwitch.checked = true;
darkMode();
}
}
Also see: Tab Triggers