HTML Code For Discussion Forum

HTML Code For Discussion Forum
Code Snippet:Discussion Board Experiment
Author: Ryan Arthur
Published: January 10, 2024
Last Updated: January 22, 2024
Downloads: 1,913
License: MIT
Edit Code online: View on CodePen
Read More

This code provides a basic HTML and CSS structure for a discussion forum. It includes a header, post list, and comment form. The CSS code styles the forum with a modern, responsive design. The JavaScript code adds some interactivity, such as the ability to toggle the visibility of the header dropdown and post comments.

This code can be used as a starting point for building a more complex discussion forum. For example, you could add features such as user authentication, voting, and moderation.

How to Create a Discussion Forum in HTML

1. First of all, load the Font Awesome CSS (for icons) and jQuery by adding the following CDN links into the head tag of your HTML document.

<link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'>
<script src='//cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

2. Create the HTML structure for the forum as follows:

<div class="container">
  <div class="response-group">
    <header>
      <h2>
        <strong>Lesson Title</strong><i class="fa fa-angle-right"></i><span class="header-dropdown-trigger">Activity Title</span>
      </h2>
    </header>
    <div class="header-dropdown">
      <div class="panel">
        <ul>
          <li>
            <h2>
              Activity Title
            </h2>
            <span>2/4</span>
            <div class="progress">
              <div class="progress__complete"></div>
            </div>
          </li>
          <li>
            <h2>
              Activity Title
            </h2>
            <span>2/4</span>
            <div class="progress">
              <div class="progress__complete"></div>
            </div>
          </li>
          <li>
            <h2>
              Activity Title
            </h2>
            <span>2/4</span>
            <div class="progress">
              <div class="progress__complete"></div>
            </div>
          </li>
          <li>
            <h2>
              Activity Title
            </h2>
            <span>2/4</span>
            <div class="progress">
              <div class="progress__complete"></div>
            </div>
          </li>
        </ul>
      </div>
    </div>
    <div class="response">
      <div class="response__number">
        1
      </div>
      <h1 class="response__title">
        Coffee emporium avondale humid german rivertown vine street findlay market historic architecture?
      </h1>
      <div class="post-group">
        <div class="post">
          <div class="post__avatar"></div>
          <h3 class="post__author">
            Lester McTester
          </h3>
          <h4 class="post__timestamp">
            Oct 13 at 8:51pm 
          </h4>
          <p class="post__body">
            Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
          </p>
          <div class="post__actions">
            <div class="button button--approve">
              <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
            </div>
            <div class="button button--deny">
              <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
            </div>
            <div class="button button--fill comment-trigger">
              <span>Comment...</span>
            </div>
            <div class="button button--flag">
              <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
            </div>
            <div class="post__comments">
              <div class="comment-group">
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
              </div>
              <div class="comment-form">
                <div class="comment-form__avatar"></div>
                <textarea></textarea>
                <div class="comment-form__actions">
                  <div class="button button--light cancel">
                    Cancel
                  </div>
                  <div class="button button--confirm">
                    Comment
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="post">
          <div class="post__avatar"></div>
          <h3 class="post__author">
            Lester McTester
          </h3>
          <h4 class="post__timestamp">
            Oct 13 at 8:51pm 
          </h4>
          <p class="post__body">
            Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
          </p>
          <div class="post__actions">
            <div class="button button--approve">
              <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
            </div>
            <div class="button button--deny">
              <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
            </div>
            <div class="button button--fill comment-trigger">
              <span>Comment...</span>
            </div>
            <div class="button button--flag">
              <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
            </div>
            <div class="post__comments">
              <div class="comment-group">
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
              </div>
              <div class="comment-form">
                <div class="comment-form__avatar"></div>
                <textarea></textarea>
                <div class="comment-form__actions">
                  <div class="button button--light cancel">
                    Cancel
                  </div>
                  <div class="button button--confirm">
                    Comment
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
        <div class="post">
          <div class="post__avatar"></div>
          <h3 class="post__author">
            Lester McTester
          </h3>
          <h4 class="post__timestamp">
            Oct 13 at 8:51pm 
          </h4>
          <p class="post__body">
            Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
          </p>
          <div class="post__actions">
            <div class="button button--approve">
              <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
            </div>
            <div class="button button--deny">
              <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
            </div>
            <div class="button button--fill comment-trigger">
              <span>Comment...</span>
            </div>
            <div class="button button--flag">
              <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
            </div>
            <div class="post__comments">
              <div class="comment-group">
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
                <div class="post">
                  <div class="post__avatar comment__avatar"></div>
                  <h3 class="post__author">
                    Lester McTester
                  </h3>
                  <h4 class="post__timestamp">
                    Oct 13 at 8:51pm 
                  </h4>
                  <p class="post__body">
                    Hamilton county river front museum center washington park breweries walnut hills findlay market christian moerlein flying pig ohio valley jazz festival union terminal fifty west coffee emporium chili.
                  </p>
                </div>
              </div>
              <div class="comment-form">
                <div class="comment-form__avatar"></div>
                <textarea></textarea>
                <div class="comment-form__actions">
                  <div class="button button--light cancel">
                    Cancel
                  </div>
                  <div class="button button--confirm">
                    Comment
                  </div>
                </div>
              </div>
            </div>
          </div>
        </div>
      </div>
    </div>
  </div>
</div>

3. Style the forum using the following CSS styles:

@charset "UTF-8";
* {
  box-sizing: border-box;
}

html {
  color: #4d4d4d;
  background-color: #ebeff1;
  font-family: "Signika";
  font-size: 16px;
  font-weight: 300;
  text-rendering: optimizeLegibility;
  -webkit-font-smoothing: antialiased;
}

h1 {
  font-size: 26px;
  font-weight: 700;
}

h2 {
  font-size: 18px;
  font-weight: 400;
}

h3 {
  font-size: 18px;
  font-weight: 700;
}

h4 {
  font-size: 12px;
  font-weight: 400;
  color: #89989c;
}

ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.comment-form__avatar, .post__avatar {
  position: absolute;
  top: 15px;
  left: 15px;
  height: 50px;
  width: 50px;
  background-color: #89989c;
  border-radius: 50%;
}

.comment-form .comment-form__actions .button {
  position: relative;
  display: inline-block;
  width: initial;
  height: 35px;
  padding: 0 10px;
  margin-left: 15px;
  background-color: white;
  color: #4ab2d9;
  line-height: 35px;
  font-weight: 400;
  text-align: center;
  border-radius: 2px;
  cursor: pointer;
  border: 1px solid #4ab2d9;
  -webkit-transition: all 0.1s;
  -o-transition: all 0.1s;
  transition: all 0.1s;
}
.comment-form .comment-form__actions .button:hover {
  background-color: #4ab2d9;
  color: #FFF;
}

.comment-form, .panel {
  position: relative;
  padding: 15px;
  background-color: #FFF;
  border-radius: 2px;
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
}

.container {
  width: 90%;
  max-width: 900px;
  margin: 50px auto 100px;
}

.response-group {
  position: relative;
  width: 100%;
  padding: 100px 15px 15px;
  background-color: #fff;
  border-radius: 2px;
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
}
.response-group > header {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: 5px 15px;
  background-color: rgba(255, 255, 255, 0.75);
  border-radius: 2px;
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  z-index: 100;
}
.response-group > header i {
  margin: 0 10px 0 20px;
}
.response-group > header .header-dropdown-trigger {
  border: 1px solid transparent;
  padding: 10px;
  border-radius: 2px;
  cursor: pointer;
}
.response-group > header .header-dropdown-trigger:after {
  content: "";
  font-family: "FontAwesome";
  font-size: 0.5em;
  line-height: 2.5;
  vertical-align: top;
  margin-left: 5px;
}
.response-group > header .header-dropdown-trigger:hover, .response-group > header .header-dropdown-trigger.active {
  border: 1px solid #cdd7dc;
}
.response-group > .header-dropdown {
  display: none;
  position: relative;
  top: -38px;
  left: -16px;
  width: calc(100% + 32px);
  padding: 15px 1px;
  background: #ebeff1;
}
.response-group > .header-dropdown.expand {
  display: block;
}
.response-group > .header-dropdown ul {
  margin: -15px;
}
.response-group > .header-dropdown li {
  padding: 1em 15px;
  cursor: pointer;
  border-bottom: 1px solid #ebeff1;
}
.response-group > .header-dropdown li h2 {
  display: inline-block;
  margin: 0;
}
.response-group > .header-dropdown li:hover h2 {
  font-weight: 700;
}
.response-group > .header-dropdown li span {
  float: right;
  margin-left: 15px;
  line-height: 1.25;
}
.response-group > .header-dropdown .progress {
  float: right;
  width: 50%;
  margin: 0.25em 0;
}

.progress {
  position: relative;
  width: 100%;
  height: 0.75em;
  border-radius: 2px;
  background-color: #ebeff1;
  box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1) inset;
}

.progress__complete {
  position: absolute;
  top: 0;
  width: 50%;
  height: 0.75em;
  background-color: #5fbc71;
  border-radius: 2px;
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
}

.response {
  position: relative;
}

.response__number {
  position: absolute;
  width: 2rem;
  height: 2rem;
  line-height: 1.8rem;
  font-size: 1.2em;
  font-weight: 700;
  text-align: center;
  color: #89989c;
  border: 2px solid #cdd7dc;
  border-radius: 50%;
}

.response__title {
  margin-left: 3.25rem;
  margin-bottom: 50px;
}

.post-group {
  margin-left: 3.5rem;
}

.post {
  position: relative;
  padding: 15px 15px 0 80px;
  margin-bottom: 50px;
  border: 1px solid #ebeff1;
  border-bottom: none;
  box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
}

.post__author {
  margin-top: 5px;
  margin-bottom: 5px;
}

.post__timestamp {
  margin-top: 0;
}

.post__actions {
  height: 40px;
  width: calc(100% + 95px);
  margin-left: -80px;
  background-color: #ebeff1;
  border-top: 1px solid #ebeff1;
}
.post__actions .button {
  float: left;
  height: 40px;
  width: 40px;
  line-height: 40px;
  text-align: center;
  vertical-align: top;
  border-right: 1px solid #cdd7dc;
}
.post__actions .button i.solid {
  display: none;
}
.post__actions .button:not(.comment):active i {
  transform: scale(1.2);
}
.post__actions .button:not(.comment-trigger):hover, .post__actions .button:not(.comment-trigger).active {
  background-color: #FFF;
  cursor: pointer;
}
.post__actions .button:not(.comment-trigger):hover i.solid, .post__actions .button:not(.comment-trigger).active i.solid {
  display: inline-block;
}
.post__actions .button:not(.comment-trigger):hover i:not(.solid), .post__actions .button:not(.comment-trigger).active i:not(.solid) {
  display: none;
}
.post__actions .button:not(.comment-trigger):hover.button--approve, .post__actions .button:not(.comment-trigger).active.button--approve {
  color: #5fbc71;
}
.post__actions .button:not(.comment-trigger):hover.button--deny, .post__actions .button:not(.comment-trigger).active.button--deny {
  color: #f26f54;
}
.post__actions .button--flag {
  width: 60px;
  border-right: none;
  font-weight: 400;
}
.post__actions .button--flag i {
  margin-right: 5px;
}
.post__actions .button--fill {
  width: calc(100% - 140px);
  padding: 0 10px;
  text-align: left;
  font-size: 16px;
  font-weight: 400;
  color: #89989c;
}

.post__comments {
  display: none;
  padding: 15px;
}

.comment-group {
  padding-bottom: 15px;
}
.comment-group .post {
  padding: 15px 15px 0 65px;
  margin-bottom: 15px;
  box-shadow: none;
}
.comment-group .post__avatar {
  height: 35px;
  width: 35px;
}

.comment-form {
  height: 100%;
  padding: 15px 15px 15px 65px;
}
.comment-form textarea {
  width: 100%;
  height: 4em;
  margin-bottom: 10px;
  font-size: 16px;
  border: 1px solid #cdd7dc;
  border-radius: 2px;
  box-shadow: 0 1px 1px #ebeff1 inset;
}
.comment-form textarea:focus {
  outline: none;
}

.comment-form__avatar {
  height: 35px;
  width: 35px;
}

.comment-form .comment-form__actions {
  text-align: right;
}
.comment-form .comment-form__actions .button {
  float: none;
}
.comment-form .comment-form__actions .button--confirm {
  border-color: #5fbc71;
  color: #5fbc71;
}
.comment-form .comment-form__actions .button--confirm:hover {
  background-color: #5fbc71;
  color: #FFF;
}
.comment-form .comment-form__actions .button--light {
  border-color: transparent;
  color: #89989c;
}
.comment-form .comment-form__actions .button--light:hover {
  background-color: #89989c;
  color: #FFF;
}

.post--commenting .post__actions {
  height: initial;
}
.post--commenting .button.comment-trigger span {
  display: none;
}
.post--commenting .post__comments {
  display: block;
  margin-top: 40px;
  border-top: 1px solid #cdd7dc;
}

4. Finally, add the following JavaScript code to your project. It handles dropdown functionality. When the user clicks on a trigger element with the class header-dropdown-trigger, it toggles the class active, expanding or collapsing the dropdown menu.

$( ".header-dropdown-trigger" ).click(function() {
  $( this ).toggleClass( "active" );
  $( ".header-dropdown" ).toggleClass( "expand" );
});

$( ".header-dropdown li" ).click(function() {
  $( ".header-dropdown-trigger" ).removeClass( "active" );
  $( ".header-dropdown" ).removeClass( "expand" );
});

$( ".button--approve" ).click(function() {
  $( this ).toggleClass( "active" );
  $( this ).siblings( '.button--deny' ).removeClass( "active" );
});

$( ".button--deny" ).click(function() {
  $( this ).toggleClass( "active" );
  $( this ).siblings( '.button--approve' ).removeClass( "active" );
});

$( ".comment-trigger" ).click(function() {
  $( this ).parent().parent().toggleClass( "post--commenting" );
});

$( ".button--flag" ).click(function() {
  $( this ).parent().parent().toggleClass( "post--commenting" );
});


$( ".button--confirm" ).click(function() {
  $( this ).parent().parent().parent().parent().parent().toggleClass( "post--commenting" );
});

$( ".button.cancel" ).click(function() {
  $( this ).parent().parent().parent().parent().parent().toggleClass( "post--commenting" );
});

That’s all! hopefully, you have successfully integrated this HTML code into your project for the discussion forum design. If you have any questions or suggestions, feel free to comment below.

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

About CodeHim

Free Web Design Code & Scripts - CodeHim is one of the BEST developer websites that provide web designers and developers with a simple way to preview and download a variety of free code & scripts. All codes published on CodeHim are open source, distributed under OSD-compliant license which grants all the rights to use, study, change and share the software in modified and unmodified form. Before publishing, we test and review each code snippet to avoid errors, but we cannot warrant the full correctness of all content. All trademarks, trade names, logos, and icons are the property of their respective owners... find out more...

Please Rel0ad/PressF5 this page if you can't click the download/preview link

X