code
Tags for showing code. This page is a short tutorial built with them: each step types itself in as you reach it.
Add motion to a page in four steps
-
Install the package
One package, no peer dependencies to wire up. Run it in your project folder.
Show the codeHide the code <script type="module"> import "motion-components/motion-code"; </script> <motion-code filename="terminal" code-lang="sh" typing typing-loop="false" typing-speed="55" copy> <script type="text/plain"> npm install motion-components </script> </motion-code> -
Import the tags you use
Each tag has its own import, so the bundle only carries what the page renders.
Show the codeHide the code <script type="module"> import "motion-components/motion-code"; </script> <motion-code filename="main.js" typing typing-loop="false" typing-speed="55" copy> <script type="text/plain"> import 'motion-components/motion-press' import 'motion-components/motion-reveal' </script> </motion-code> -
Wrap your HTML
Put the tag around the element that should move. The button keeps its own markup and styles.
Show the codeHide the code <script type="module"> import "motion-components/motion-code"; </script> <motion-code filename="index.html" typing typing-loop="false" typing-speed="55" copy> <script type="text/plain"> <motion-press> <button class="buy">Add to cart</button> </motion-press> </script> </motion-code> -
Tune it with attributes
Attributes set the spring. A deeper press and more bounce make the same button feel softer.
Show the codeHide the code <script type="module"> import "motion-components/motion-code"; </script> <motion-code filename="index.html" typing typing-loop="false" typing-speed="55" copy> <script type="text/plain"> <motion-press scale="0.86" bounce="0.7"> <button class="buy">Add to cart</button> </motion-press> </script> </motion-code>
Everything else a code block can do
Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code filename="hero.html" typing typing-speed="40" typing-hold="2">
<script type="text/plain">
<motion-headline by="words">
Motion that feels physical
</motion-headline>
</script>
</motion-code>Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code hide-chrome>
<script type="text/plain">
.card {
--mc-spotlight-color: rgb(250 204 21 / 0.25);
border-radius: 1rem;
}
</script>
</motion-code>Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code filename="theme.css" compact copy copy-label>
<script type="text/plain">
:root {
--mc-color-accent: #2563eb;
--mc-color-yellow: #a16207;
}
</script>
</motion-code>Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code filename="package.json" compact>
<script type="text/plain">
{
"dependencies": {
"motion-components": "^1.2.0"
}
}
</script>
</motion-code>Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code filename="build.py" compact>
<script type="text/plain">
for page in pages:
render(page, theme="dark")
</script>
</motion-code>Show the codeHide the code
<script type="module">
import "motion-components/motion-code";
</script>
<motion-code filename="settings" code-lang="js" compact style="--mc-code-keyword: #f472b6; --mc-code-string: #4ade80; --mc-code-num: #facc15">
<script type="text/plain">
const spring = { stiffness: 320, damping: 24 }
export default { theme: "dark", spring }
</script>
</motion-code>Code inside a sentence
Install with
Show the codeHide the code
<script type="module"> import "motion-components/motion-code-inline"; </script> <p> Install with <motion-code-inline copy-visible>npm install motion-components</motion-code-inline>, then wrap any button in <motion-code-inline copy>motion-press</motion-code-inline> and set <motion-code-inline>scale="0.9"</motion-code-inline> for a deeper press. </p>