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.
<!-- I made this pen to try out and illustrate some of the subtle shadow effects you can create using just text-shadow and transitions. The pattern effect also uses a small piece of SVG.
Inspired by this animated gif I saw on dribbble (https://dribbble.com/shots/1881907-Love?list=shots&sort=recent&timeframe=now&offset=18).
I’ve included the Sass mixins I use to make the text-shadow effect, but you could also just use compass which has these mixins baked straight in.
The CSS only effects (first 4) work in Chrome/Firefox/Safari/IE10+.
The final pattern effect works perfectly in Chrome, Firefox and IE seems to lose the text-shadow for some reason and it completely flips out in Safari!
-->
<h1>A collection of CSS Text shadow and pattern effects <a href="https://twitter.com/AshNolan_" target="blank">created by @AshNolan_</a></h1>
<h2 class="headingOuter">Push down (shadow effect)</h2>
<div class="headingWrapper color-bright">
<a href="" class="header header--pushDown header--shadow" title="HOVER ME">HOVER ME</a>
</div>
<div class="headingWrapper">
<a href="" class="header header--pushDown header--shadow" title="HOVER ME">HOVER ME</a>
</div>
<h2 class="headingOuter">Raise up (shadow effect)</h2>
<div class="headingWrapper color-bright">
<a href="" class="header header--raiseUp header--shadow">HOVER ME</a>
</div>
<div class="headingWrapper">
<a href="" class="header header--raiseUp header--shadow">HOVER ME</a>
</div>
<h2 class="headingOuter">Push down (merging into page)</h2>
<div class="headingWrapper color-bright">
<a href="" class="header header--pushDown">HOVER ME</a>
</div>
<div class="headingWrapper">
<a href="" class="header header--pushDown">HOVER ME</a>
</div>
<h2 class="headingOuter">Raise up (emerging from page)</h2>
<div class="headingWrapper color-bright">
<a href="" class="header header--raiseUp">HOVER ME</a>
</div>
<div class="headingWrapper">
<a href="" class="header header--raiseUp">HOVER ME</a>
</div>
<h2 class="headingOuter">Raised up (emerging from bg) with pattern</h2>
<div class="headingWrapper color-bright">
<a href="#" class="header header--raiseUp header--svg">
<svg>
<defs>
<linearGradient id="stripedColor" x1="0" x2="0" y1="0%" y2="4%" spreadMethod="repeat">
<stop offset="0%" stop-color="#e62915"/>
<stop offset="50%" stop-color="#e62915"/>
<stop offset="51%" stop-color="#fff"/>
<stop offset="99%" stop-color="#fff"/>
<stop offset="100%" stop-color="#e62915"/>
</linearGradient>
</defs>
<text y="1.2em">Hover Me</text>
</svg>
</a>
</div>
<div class="headingWrapper">
<a href="#" class="header header--raiseUp header--svg">
<svg>
<defs>
<linearGradient id="striped" x1="0" x2="0" y1="0%" y2="4%" spreadMethod="repeat">
<stop offset="0%" stop-color="#e62915"/>
<stop offset="50%" stop-color="#e62915"/>
<stop offset="51%" stop-color="#fff"/>
<stop offset="99%" stop-color="#fff"/>
<stop offset="100%" stop-color="#e62915"/>
</linearGradient>
</defs>
<text y="1.2em">Hover Me</text>
</svg>
</a>
</div>
/*
The following mixin is taken and edited from this pen - https://codepen.io/hugo/pen/xzjGB
I have added outlineColor to allow the addition of a text-shadow outline for the text.
*/
@function pow($number, $exp) {
$value: 1;
@if $exp > 0 {
@for $i from 1 through $exp {
$value: $value * $number;
}
}
@else if $exp < 0 {
@for $i from 1 through -$exp {
$value: $value / $number;
}
}
@return $value;
}
@function fact($number) {
$value: 1;
@if $number > 0 {
@for $i from 1 through $number {
$value: $value * $i;
}
}
@return $value;
}
@function pi() {
@return 3.14159265359;
}
@function rad($angle) {
$unit: unit($angle);
$unitless: $angle / ($angle * 0 + 1);
// If the angle has 'deg' as unit, convert to radians.
@if $unit == deg {
$unitless: $unitless / 180 * pi();
}
@return $unitless;
}
@function sin($angle) {
$sin: 0;
$angle: rad($angle);
// Iterate a bunch of times.
@for $i from 0 through 10 {
$sin: $sin + pow(-1, $i) * pow($angle, (2 * $i + 1)) / fact(2 * $i + 1);
}
@return $sin;
}
@function cos($angle) {
$cos: 0;
$angle: rad($angle);
// Iterate a bunch of times.
@for $i from 0 through 10 {
$cos: $cos + pow(-1, $i) * pow($angle, 2 * $i) / fact(2 * $i);
}
@return $cos;
}
@mixin shade($type, $color: #3498db, $borderColor: #fff, $depth: 20, $angle: 135deg, $long: false, $fade: false) {
$angle: ($angle - 90);
$x: 1.1 * cos($angle) + 0px;
$y: 1.1 * sin($angle) + 0px;
$darken: (lightness($color)/$depth)/2;
$opacify: 0;
$shadow: ();
@if $long == true{
$darken:0;
}
@if $fade == true {
$opacify: (opacity($color)/$depth) ;
// added this for rendering in some browsers, remove if you like.
@include translateZ(0);
}
@for $i from 1 through $depth {
$shadow: $shadow, $i*$x $i*$y 0 hsla(hue($color) , saturation($color), (lightness($color) - ($i * $darken)), 1 - ($i * $opacify));
}
#{$type}-shadow: 1.5px 1.5px 0 $borderColor,
0px 1.5px 0 $borderColor,
-1.5px -1.5px 0 $borderColor,
-1.5px -1.5px 0 $borderColor,
-1.5px 1.5px 0 $borderColor,
1.5px -1.5px 0 $borderColor,
$shadow;
}
//mixin to provide just a basic outline for the text
@mixin outline($color: #fff) {
text-shadow: 1.5px 1.5px 0 $color,
-1.5px -1.5px 0 $color,
-1.5px -1.5px 0 $color,
-1.5px 1.5px 0 $color,
1.5px -1.5px 0 $color;
}
// Define the fonts used in the Pen
@import url(https://fonts.googleapis.com/css?family=Francois+One);
@import url(https://fonts.googleapis.com/css?family=PT+Sans);
// Define the colors
$pink : #f89bb4;
$pinkPastel : #ebaca5;
$pinkDark : #e62915;
$pinkGrayed : #d38076;
$grayLight : #cac6c5;
$offWhite : #e7e7e7;
* {
box-sizing: border-box;
}
body {
font-size: 62.5%;
}
//basic header styles
h1, h2, h3 {
font-family: 'PT Sans', sans-serif;
text-transform: uppercase;
}
h1 {
font-size: 2.4em;
background-color: rgba(41, 41, 41, 1);
text-align: center;
padding: 20px;
margin: 0;
color: #fff;
a {
display: block;
margin-top: 10px;
text-transform: none;
color: #aaa;
font-size: 16px;
text-decoration: none;
}
}
h2 {
font-size: 1.6em;
margin: 0;
padding: 10px;
border-top: 1px solid #ccc;
}
h3 {
margin: 0;
padding: 10px;
}
// Outer heading wrapper (for descriptions, not for the actual effects)
.headingOuter {
background: #f1f1f1;
text-align: center;
margin-top: 30px;
border-top: 1px solid #333;
border-bottom: 1px solid #333;
&:first-child {
margin-top: 0;
}
h1 + & {
margin-top: 10px;
}
}
.headingWrapper {
text-align: center;
background-color: #fff;
padding: 10px;
}
// default header class – used on all examples
.header {
display: inline-block;
text-align: center;
font-family: 'Francois One', Helvetica, Arial, sans-serif;
font-size: 96px;
color: $offWhite;
text-decoration: none;
@include outline($grayLight);
transition: all 400ms ease-in-out;
}
// effect for pushing the text down onto the page
// default is the letters emerging from the page and merging back down on hover
.header--pushDown {
@include shade(text, #aaa, #333, 10, 135deg, true);
&:hover {
transform: translate(9px, 9px);
@include outline($grayLight);
}
}
// raising text from page when hovered, so flipped state to header--pushDown class
.header--raiseUp {
&:hover {
transform: translate(-9px, -9px);
@include shade(text, #aaa, #333, 10, 135deg, true);
}
}
// creates a shadow effect, rather than a raised lettering effect
// simply by adjusting the translate position a little
.header--shadow {
&:hover {
transform: translate(5px, 0);
}
&.header--raiseUp {
&:hover {
transform: translate(-5px, 0);
}
}
}
//Brighter colored text
.color-bright {
background-color: $pinkPastel;
& .header {
color: $pink;
@include outline($pinkGrayed);
}
//push down text
& .header--pushDown {
@include shade(text, $pinkDark, #fff, 10, 135deg, true);
&:hover {
@include outline($pinkGrayed);
}
}
//raise up text
& .header--raiseUp:hover {
@include shade(text, $pinkDark, #fff, 10, 135deg, true);
}
}
// SVG Pattern text effect
// Same as the above but with a pattern text effect on hover
// Played around with this for a while – cannot be done with background clip and a CSS gradient as the
// text-shadow always appears in front of the background (unless you have no background color on the wrapping element)
// Therefore, use SVG linearGradient and animate the stop points using CSS
svg {
line-height: 1.2;
width: 410px;
height: 1.5em;
}
.header--svg {
text,
stop {
transition: all 350ms ease-in-out;
}
text {
text-transform: uppercase;
fill: url(#striped);
@include outline($grayLight);
}
&:hover text {
@include shade(text, #aaa, #333, 10, 135deg, true);
}
//animate gradient stop points
& stop {
stop-color: $offWhite;
}
&:hover stop {
stop-color: #fff;
&:nth-child(2),
&:nth-child(3) {
stop-color: $pinkGrayed;
}
}
}
// Brighter version of the SVG pattern text
.color-bright {
& .header--svg {
text {
fill: url(#stripedColor);
@include outline($pinkGrayed);
}
&:hover text {
@include shade(text, $pinkDark, #fff, 10, 135deg, true);
}
}
& stop {
stop-color: $pink;
}
& .header--svg:hover stop {
&:nth-child(2),
&:nth-child(3) {
stop-color: #ed5751;
}
}
}
Also see: Tab Triggers