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.
<div id="root"></div>
@import url('https://fonts.googleapis.com/css?family=Montserrat:700|Open+Sans:400,700');
:root {
--text-color: rgba(38, 40, 45, 1);
--secondary-text-color: rgba(255, 255, 255, .65);
--hidden-text-color: rgba(38, 40, 45, 0);
--primary-color: white;
--secondary-color: rgba(103, 118, 140, 1);
--secondary-color-hover: rgba(70, 146, 252, 1);
--tertiary-color: rgba(215, 219, 230, 1);
}
* {
padding: 0;
margin: 0;
border: 0;
box-sizing: border-box;
}
body {
background-color: var(--tertiary-color);
font-family: 'Open Sans';
}
.tabs {
font-weight: 400;
}
.tabs a {
text-decoration: none;
color: inherit;
}
.tabs h2 {
font-size: 36px;
margin-bottom: 15px;
text-transform: capitalize;
font-family: 'Montserrat', sans-serif;
}
.tab {
padding: 14px 12px 14px 20px;
background-color: var(--secondary-color);
color: var(--secondary-text-color);
width: max-content;
float: left;
margin-left: -1px;
position: relative;
z-index: 0;
transition: top .5s ease 0s,
border .5s ease 0s,
color .5s ease 0s,
background-color .5s ease 0s,
border-top-left-radius .5s ease 0s;
top: 0;
}
.tab:hover {
cursor: pointer;
top: -3px;
background-color: var(--secondary-color-hover);
color: var(--text-color);
z-index: 2;
border-top-left-radius: 5px;s
}
.tab::after {
content: '';
display:block;
width: 0;
height: 0;
border-right: 20px transparent solid;
border-bottom: 60px var(--secondary-color) solid;
z-index: 0;
position: absolute;
top:0;
left: 100%;
transition: border-bottom .5s ease 0s;
}
.tab:hover::after {
content: '';
display:block;
width: 0;
height: 0;
border-right: 20px transparent solid;
border-bottom: 60px var(--secondary-color-hover) solid;
z-index: 2;
position: absolute;
top:0;
left: 100%;
}
.tab:first-child {
margin-left: 0;
border-top-left-radius: 5px;
}
.tab:focus {
outline: none;
}
.tabs .active {
top: -3px;
color: var(--text-color);
z-index: 3;
background-color: var(--primary-color);
border-top-left-radius: 5px;
}
.tab.active::after {
border-bottom: 60px var(--primary-color) solid;
}
section {
margin: 15px auto;
width: 700px;
}
.tabs menu ul {
list-style: none;
}
.tabs menu + div {
clear: both;
margin-top: 15px;
padding: 15px 0;
color: white;
line-height: 1.5;
color: rgba(255,255,255,.6);
position: relative;
}
.tabs menu + div > div > hr {
height: 2px;
width: 33%;
opacity: 0;
transition: opacity .5s ease 0s;
margin-bottom: 15px;
background-color: var(--secondary-color);
}
.tabs menu + div > div {
visibility: hidden;
color: var(--hidden-text-color);
transition: color .5s ease 0s;
padding: 20px;
position: absolute;
top: 0;
width: 100%;
background-color: rgb(24, 26, 30);
}
.tabs menu + div > .active {
visibility: visible;
color: var(--text-color);
border-bottom: 1px var(--tertiary-color) solid;
transition: color 1s ease 0s;
border-radius: 0 5px 5px 5px;
}
.tabs menu + div > div.active > hr {
opacity: .5;
}
const Component = React.Component;
const TAB_DATA = [
["about", "lorem ipsum dolor sit amet"],
["contact", "Curabitur in augue erat. Vestibulum in fermentum ante, sit amet consectetur neque. Maecenas tempor nisl sollicitudin, blandit sapien ut, fermentum metus."],
["portfolio", "Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Aliquam aliquam, nisi vitae maximus tincidunt, justo leo auctor neque, et fermentum ante libero ac libero."],
["cool stuff", "Nullam lacinia ipsum metus, ut varius tortor egestas non. Fusce lobortis, dolor ut venenatis posuere, diam neque mattis risus, vulputate sodales eros urna a turpis. Vivamus pretium condimentum faucibus. Nullam laoreet, mauris vitae vulputate vulputate, justo felis facilisis lorem, sed elementum metus leo eget nisl."],
["another tab", "Vivamus sit amet ante vitae tortor condimentum blandit. Nunc a purus dui. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec dapibus porttitor diam. Aenean sit amet accumsan orci. Phasellus eget justo ante. Morbi fringilla aliquam lectus."],
["another blab", "Vivamus sit amet ante vitae tortor condimentum blandit. Nunc a purus dui. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Donec dapibus porttitor diam. Aenean sit amet accumsan orci. Phasellus eget justo ante. Morbi fringilla aliquam lectus."]
];
class Tabs extends Component {
constructor(props) {
super(props);
this.state = {
active: 0
}
}
clickHandler = (e) => {
this.setState({
active: parseInt(e.currentTarget.attributes.tabIndex.value)
})
}
render() {
let tabs = [];
let contents = [];
TAB_DATA.map(([label, text], i) => {
const myStyle = {
zIndex: this.state.active === i ? TAB_DATA.length : TAB_DATA.length - i - 1
};
tabs.push(<li
className={this.state.active === i ? "tab active" : "tab" }
key={label}
tabIndex={i}
onClick={this.clickHandler}
style={myStyle}>
<a href={"#" + label}>{label}</a>
</li>);
contents.push(<div style={{zIndex: TAB_DATA.length}} className={this.state.active === i ? "active" : "" } key={label}><h2 id={label}>{label}</h2><hr/><p>{text}</p></div>);
});
return (
<section className="tabs">
<menu>
<ul>
{tabs}
</ul>
</menu>
<div>
{contents}
</div>
</section>);
}
}
const App = () => {
return (
<Tabs />
)
}
ReactDOM.render(<App />, document.getElementById("root"));
Also see: Tab Triggers