Ubuntu Terminal in CSS
Tags: css, codepen, webdev, showdev
Published: 2020-02-15 02:50:28


*This was originally published on [codinhood.com](https://codinhood.com/micro/ubuntu-terminal-css)*

The design and color scheme for Ubuntu and the Ubuntu terminal are relatively unique and immediately recognizable by anyone who's used Ubuntu before. Recreating the Ubuntu terminal in CSS is a fun little exercise to practice your CSS skills. 

{% codepen https://codepen.io/codypearce/pen/JmOQXB %}

## Ubuntu Font

For those that do not know, Ubuntu actually has it's [own font](https://design.ubuntu.com/font/) in three different styles: regular, condensed, and monospace. The Ubuntu terminal uses Ubuntu regular for the title in the toolbar and Ubuntu Monospace for the text within the terminal. Both of these can be found and sourced from [Google Fonts](https://fonts.google.com/specimen/Ubuntu).

## Toolbar

The Ubuntu terminal toolbar consists of three buttons and the title which consists of the user and the system name. The background of the toolbar is actually a slight linear gradient of dark greys. Additionally, the topbar right and left corners are rounded unlike the bottom right and left corners of the whole terminal.

```css

.Terminal__Toolbar {
  background: linear-gradient(#504b45 0%,#3c3b37 100%);
  width: 100%;
  padding: 0 8px;
  box-sizing: border-box;
  height: 25px;
  display: flex;
  align-items: center;
  border-top-left-radius: 6px;
  border-top-right-radius: 6px;
}

.Toolbar__user {
  color: #d5d0ce;
  margin-left: 4px;
  font-size: 12px;
  line-height: 14px;
  margin-bottom: 1px;
}
```

## Toolbar Buttons

The toolbar buttons also have a slight grey linear-gradient, as well as a text-shadow, and box-shadow. We could use icons to render the toolbar button contents but to keep it simple we will use [HTML Character Entities](https://html.spec.whatwg.org/multipage/named-characters.html#named-character-references) for each.

`&#10005;` is an X

`&#9472;` is a line

`&#9723;` is a box

```html
<button class="Toolbar__button Toolbar__button--exit">&#10005;</button>
<button class="Toolbar__button">&#9472;</button>
<button class="Toolbar__button">&#9723;</button>
```

```css
.Toolbar__buttons {
  display: flex;
  align-items: center;
}

.Toolbar__button {
  width: 12px;
  height: 12px;
  box-sizing: border-box;
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 100%;
  padding: 0;
  font-size: 7px;
  background: linear-gradient(#7d7871 0%, #595953 100%);
  text-shadow: 0px 1px 0px rgba(255,255,255,0.2);
  box-shadow: 0px 0px 1px 0px #41403A,0px 1px 1px 0px #474642;
  border: none;
  margin-right: 4px;

}
.Toolbar__button:hover {
  cursor: pointer;
}
.Toolbar__button--exit {
  background: #f25d2b;
  background: linear-gradient(#f37458 0%, #de4c12 100%);
  background-clip: padding-box;
}
.Toolbar__button:focus {
  outline: none;
}
```

## Terminal Body and Text

The body of the terminal is even simpler, simply a rectangle with a specific purple background and the appropriate text for a terminal inside. The important part here to get the colors right since the Ubuntu terminal is so distinctive with its colors. The text "Welcome to Ubuntu!" and dollar sign are `#ddd`, the name and system are a bright green `#87d441`, and the location (which is just ~ right now) is a washed-out blue/grey `#6d85a9`.

```css

.Terminal__body {
  background: rgba(56, 4, 40, .9);
  height: calc(100% - 25px);
  margin-top: -1px;
  padding-top: 2px;
  font-family: 'Ubuntu mono';
}
.Terminal__text {
  color: #ddd;
}

.Terminal__Prompt {
  margin-top: 10px;
  display: flex;
}

.Prompt__user {
  color: #87d441;
}
.Prompt__location {
  color: #6d85a9;
}
.Prompt__dollar {
  color: #ddd;
}

```

## Ubuntu Cursor Animation

Finally, add the terminal cursor, which is just a white block by default. We can animate the cursor like it's blinking by changing the opacity from `0` to `1`. To make the animation loop, we can add `infinite` and `alternate` to the `animation` property so the cursor will animate from `0` to `1` then animate from `1` to `0` then animate from `0` to `1` over and over again.

```css
.Prompt__cursor {
  height: 17px;
  width: 8px;
  background: white;
  display: block;
  margin-left: 8px;
  animation: 2000ms ease infinite alternate blink;
}

@keyframes blink {
  0% {
    opacity: 0;
  }
  100% {
    opacity: 1;
  }
}
```

## Expanding the demo 

We could expand this demo by using a library like [typed.js](https://github.com/mattboldt/typed.js/) to show the terminal text animating a command. Or we could put a `<textarea>` within the terminal and allow users to type.