I built a pop-out drawer animation with HTML and CSS — cover illustration
Last updated:

I built a pop-out drawer animation with HTML and CSS


I tried something like this.

When you hover your cursor over the link, the drawer moves and your avatar appears. You can create it while moving HTML and CSS samples.

Tested and working demo and all code available on public site

A screen where an avatar and paper pop out from the blog drawer
A screen where an avatar and paper pop out from the blog drawer
Try out the interactive demo ↗
Table of contents of this article

I like white backgrounds. But it's a bit quiet...

When creating the home for Ryu's Lab, I started adjusting the appearance from that point on. Rather than just arranging the items neatly, I wanted it to be a place where something happens when you touch it, like a toy box.

Therefore, we have added a mechanism in which the avatar will appear on the pull-out link. This time, I tried actually operating the published page to see how it looked.

When closed, the entrance is open for normal reading.

It usually looks like this. Profile, work, blog, SNS, diary. You can read where you're going without doing anything.

5 normal drawers where your avatar is hidden
Actual screen at normal time. Not only the moving parts but also the destination label are left behind.

A drawer is a link that takes you to a page. Even if you don't understand the effect that pops up, you can press the button and go to the desired page. I'm adding a little bit of play to that foundation.

When you touch it, the box shifts to reveal your face.

When I shifted my focus to the "Blog" drawer, the frame shifted slightly and an avatar and paper came out from above.

Avatar and paper using GitHub's face image come out of the blog drawer
This time I took a picture by operating with the Tab key on the keyboard. The blue frame indicates the focus. The same display toggle is used when hovering over the cursor.

The face is the GitHub profile picture. The body and arms are separate small parts. Rather than making everything into one picture and moving it, I combine the face, body, and accessories.

The drawer moves first, and a little later a face appears. Rather than moving at exactly the same time, I wanted it to feel like it reacted briefly.

If you look inside, you'll find a surprisingly simple mechanism.

We are not preparing a three-dimensional box. If you check the implementation, you will see that the position of the drawer has been shifted by 9px to the left and 3px to the bottom, and the position of the shadow has also been changed.

The avatar is usually hidden at the bottom and is moved up when a reaction occurs. The way it moves when it comes out has been adjusted so that it bounces a little.

Rather than showing the amount of code, I thought it would be easier to convey the message by looking at the screen to see what was different, so this photo shows the same page as it would normally be.

I looked at another drawer

Next, when you return the focus to ``work'', a computer will appear instead of paper.

Actual home screen focusing on work drawer
Actual screen of work. A computer will appear next to your avatar. I also confirmed this using the keyboard.

In terms of implementation, there are some differences, such as waving your hand in the profile and moving like a pencil in the diary. The photos I took this time are of two types: work and blog.

It doesn't seem like all you have to do is move.

When checking the screen, you can see that the avatar will appear at the top of the drawer, so it will overlap the drawer one level above. As much as we add play, we also want to see how easy the text is to read.

Also, smartphones do not have a mouse cursor. Rather than just showing movement, we make sure that you can read the label on a regular basis. This time's verification was based on keyboard operations on a PC, and is not a record of actual verification of tap operations on a smartphone.

It's a bit of a gimmick, but it looks like it'll be fun if people realize that when you touch it, something comes out. I hope to increase the number of such detours little by little.

Open the actual “Labo Drawer”

Verification date: November 4, 2026. Screenshots were taken by actually operating the public site. How it workshome codeandavatar codeI compared it with

If you want to create the same thing, try this one file first.

This is for those who want to add it to their own site. First, I made a sample that is a smaller version of the actual device. All you need is a text editor and a browser. No Node.js or library installation required.

Open the moving sample / Download HTML as ZIP

The actual version is a ``link that moves when pressed,'' but this sample is divided into a ``drawer that opens when you press'' and a ``link inside'' so that you can try out the movement on a smartphone. Faces are emojis that are easy to distribute.

From download to first operation check

Here we will proceed on a Mac. First, download the ZIP file above and double-click it. expanded index.html Right-click and select Safari or Chrome from "Open with".

Display landmarks: If a yellow box appears saying, ``Let's make a drawer.'', the file is open. There is no need to upload it to the internet.

  1. Hover over the box → An emoji face will appear.
  2. Click on the box → A link that says ``Go to article location'' will appear inside.
  3. Click that link → Move to "Article Location" on the page. The amount of movement may be small on short screens. The end of the URL is #destination Then you can check your destination.
  4. Press the box again → The links inside will be hidden. The face remains visible while the cursor or keyboard focus remains on the box.

Also on your keyboard, check if the box is framed by pressing the Tab key and the links inside are opened and closed by pressing Enter. Depending on the browser and OS tab settings, you may need to enable keyboard navigation first.

A screen where the distribution HTML is actually opened in a browser and a drawer is opened.
Run the distributed code itself in your browser. I confirmed that click opens and enter closes.

HTML/CSS that works as is

All the code is the same as the HTML included in the ZIP. Just follow the steps above first and then read the parts you are interested in.

<!doctype html>
<html lang="ja">
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<title>飛び出す引き出し・最小サンプル</title>
<style>
* { box-sizing: border-box; }
body { margin: 0; padding: 32px 20px; color: #303d48; background: #fff;
  font-family: system-ui, sans-serif; line-height: 1.8; }
main { max-width: 540px; margin: auto; }
h1 { font-size: 26px; }
.cabinet { padding: 85px 24px 24px; background: #eee9df;
  border: 2px solid #303d48; border-radius: 16px; }
.drawer { --color: #fff0b8; position: relative; }
.drawer summary { position: relative; padding: 24px; list-style: none;
  border: 2px solid #303d48; border-radius: 8px; background: var(--color);
  box-shadow: 0 5px 0 #303d48; cursor: pointer;
  transition: transform .2s, box-shadow .2s; }
.drawer summary::-webkit-details-marker { display: none; }
.drawer summary::after { content: '▰'; float: right; }
.drawer summary:focus-visible { outline: 3px solid #315f91; outline-offset: 5px; }
/* 上側は空ける。隠すのはキャラクター用の窓だけ。 */
.window { position: absolute; right: 18px; top: -72px; width: 84px;
  height: 72px; overflow: hidden; pointer-events: none; }
.avatar { display: block; font-size: 54px; text-align: center;
  transform: translateY(80px); opacity: 0;
  transition: transform .5s .1s cubic-bezier(.2,1.5,.4,1), opacity .2s; }
.drawer:is(:hover, :focus-within, [open]) summary {
  transform: translate(-6px, 2px); box-shadow: 6px 7px 0 #303d48; }
.drawer:is(:hover, :focus-within, [open]) .avatar {
  transform: translateY(0); opacity: 1; }
.contents { margin-top: 18px; padding: 16px; background: #fff;
  border-radius: 8px; }
a { color: #245b89; }
#destination { margin-top: 36px; padding: 20px; background: #eef5ef; }
@media (prefers-reduced-motion: reduce) {
  .drawer summary, .avatar { transition: none; }
}
</style>
<main>
  <h1>引き出しを、ひとつ作ってみる。</h1>
  <p>カーソルを重ねると顔が出ます。クリック・タップ・Enterで開閉できます。</p>
  <div class="cabinet">
    <details class="drawer">
      <summary>
        <span class="window" aria-hidden="true"><span class="avatar">🙂</span></span>
        ブログのひきだし
      </summary>
      <div class="contents"><a href="#destination">記事の置き場所へ進む →</a></div>
    </details>
  </div>
  <section id="destination"><h2>記事の置き場所</h2><p>ここまで移動できれば、リンクも動いています。</p></section>
</main>
</html>

There are three things you need to change for your own site:

Use a code editor such as VS Code for editing.index.html Drag it to the editor, press Command + F to find and replace the characters below, and press Command + S to save. Return to your browser and reload with Command+R. Make the following changes one location at a time.

  • Name:ブログのひきだし to the word you want to display.
  • Destination: Change href="#destination" to your blog URL. You can then remove the test section id="destination" section.
  • Color:--color: #fff0b8 to your favorite color. Also check the contrast with the text.

Confirmation: After changing the name, check the drawer label; after changing the color, check its background; after changing the URL, check the link destination. If the text has not changed, make sure you edited the same file you opened in the browser. If the file is named index.html.txt, save it again as HTML.

Once you've done this, it's complete. Below is an additional arrangement. If you want to make your own avatar, go to the same folder as the HTML. avatar.png of the emoji span Replace with the following image.

<img class="avatar" src="avatar.png" alt="" width="64" height="64">

For CSS .avatar { width: 64px; height: 64px; object-fit: cover; margin: 4px auto; } Add. The image is a decoration, so in this example I'm using an empty alt. Leave the name and link destination in text outside the image.

Why does it move? If you know this, you can adjust it.

translateY(80px) I hid my face under the window and reacted. translateY(0) I'm returning it to.transition is a setting that shows the movement over time rather than in an instant.

:hover is the cursor,:focus-within is keyboard operation,[open] corresponds to the open state.details and summary There is no JavaScript for opening and closing as the standard functions are used.

Settings that reduce movement transition: none I'm doing it. The ability to open and close remains the same, but the movement animation is omitted.

What to look for when the display is strange

  • No face:In a drawer or outside box overflow: hidden Check that it is not attached. What to hide .window Only inside.
  • Only the image does not appear:avatar.png Check that the name, extension, and save location are correct.
  • Can't proceed to link:Open this sample once and click the link inside. summary is not a movement button.
  • Overlaps characters in another drawer:If you are arranging more than one, leave enough space for your face to appear at the top. First margin-top: 85px Please adjust using this as a guide.

Confirmation of completion:Face appears/Open/close with click or Enter/Move with links inside. If you can confirm these three in your own environment, the first one is complete.

The specifications of the elements used for opening and closing are as follows:Explanation of MDN details elementBut you can check it.

If you rounded the corners and the protruding decorations are cut off,overflow: How to separate hidden and achieve both rounded and protruding cornersAlso try it. There is a comparison demo before and after modification and the completed HTML.