<div id="container">
  <h3>Choose your text alignment</h3>
  <div id="buttons">
    <button id="left" class="active">Left</button>
    <button id="center">Center</button>
    <button id="right">Right</button>
    <button id="justify">Justify</button>
  <div id="text" style="text-align: left;">

    <p>The studio was filled with the rich odour of roses, and when the light summer wind stirred amidst the trees of the garden, there came through the open door the heavy scent of the lilac, or the more delicate perfume of the pink-flowering thorn.</p>

    <p>From the corner of the divan of Persian saddle-bags on which he was lying, smoking, as was his custom, innumerable cigarettes, Lord Henry Wotton could just catch the gleam of the honey-sweet and honey-coloured blossoms of a laburnum, whose tremulous
      branches seemed hardly able to bear the burden of a beauty so flamelike as theirs; and now and then the fantastic shadows of birds in flight flitted across the long tussore-silk curtains that were stretched in front of the huge window, producing
      a kind of momentary Japanese effect, and making him think of those pallid, jade-faced painters of Tokyo who, through the medium of an art that is necessarily immobile, seek to convey the sense of swiftness and motion. The sullen murmur of the bees
      shouldering their way through the long unmown grass, or circling with monotonous insistence round the dusty gilt horns of the straggling woodbine, seemed to make the stillness more oppressive. The dim roar of London was like the bourdon note of
      a distant organ.</p>

    <p>In the centre of the room, clamped to an upright easel, stood the full-length portrait of a young man of extraordinary personal beauty, and in front of it, some little distance away, was sitting the artist himself, Basil Hallward, whose sudden disappearance
      some years ago caused, at the time, such public excitement and gave rise to so many strange conjectures.</p>

    <p>As the painter looked at the gracious and comely form he had so skilfully mirrored in his art, a smile of pleasure passed across his face, and seemed about to linger there. But he suddenly started up, and closing his eyes, placed his fingers upon
      the lids, as though he sought to imprison within his brain some curious dream from which he feared he might awake.</p>

    <p>"It is your best work, Basil, the best thing you have ever done," said Lord Henry languidly. "You must certainly send it next year to the Grosvenor. The Academy is too large and too vulgar. Whenever I have gone there, there have been either so many
      people that I have not been able to see the pictures, which was dreadful, or so many pictures that I have not been able to see the people, which was worse. The Grosvenor is really the only place."</p>

  <p><em>The Picture of Dorian Gray</em>, by Oscar Wilde; via <a href="https://www.shmoop.com/picture-dorian-gray/chapter-1-full-text.html">via Schmoop</a></p>

// https://flatuicolors.com/palette/in

html {
  margin: 0;
  padding: 0;
  background-color: #2c3a47;

#buttons {
  display: grid;
  grid-gap: 0.2em;
  grid-template-columns: repeat(auto-fit, minmax(100px, 1fr));
  grid-auto-rows: max-content;
  & button {
    color: #F8EFBA;
    background-color: #2C3A47;
    border: 0;
    padding: 0.4em 1em;
    font-size: 1em;
    cursor: pointer;
    &.active {
      background-color: #F97F51;
    &:focus {
      outline: 3px solid #D6A2E8;
    &:hover {
      opacity: 0.9;

#container {
  transition: all 300ms ease-in-out;

  margin: 1em;
  padding: 1em;

  max-width: 600px;

  background-color: #f8efba;
  color: #2c3a47;

  & p {
    font-size: 1.2em;
    font-family: sans-serif;

a {
  &:link {
    color: #1b9cfc;
  &:visited {
    color: #82589f;
  &:hover {
    color: #55e6c1;
  &:active {
    color: #f97f51;
View Compiled
const buttons = $('#buttons > button');
buttons.on('click', function() {
  const id = $(this).attr('id');
  $('#text').css('text-align', id);

External CSS

This Pen doesn't use any external CSS resources.

External JavaScript

  1. https://cdnjs.cloudflare.com/ajax/libs/jquery/3.4.1/jquery.min.js