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: 4,987
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.

  1. <link rel='stylesheet' href='https://maxcdn.bootstrapcdn.com/font-awesome/4.2.0/css/font-awesome.min.css'>
  2. <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:

  1. <div class="container">
  2. <div class="response-group">
  3. <header>
  4. <h2>
  5. <strong>Lesson Title</strong><i class="fa fa-angle-right"></i><span class="header-dropdown-trigger">Activity Title</span>
  6. </h2>
  7. </header>
  8. <div class="header-dropdown">
  9. <div class="panel">
  10. <ul>
  11. <li>
  12. <h2>
  13. Activity Title
  14. </h2>
  15. <span>2/4</span>
  16. <div class="progress">
  17. <div class="progress__complete"></div>
  18. </div>
  19. </li>
  20. <li>
  21. <h2>
  22. Activity Title
  23. </h2>
  24. <span>2/4</span>
  25. <div class="progress">
  26. <div class="progress__complete"></div>
  27. </div>
  28. </li>
  29. <li>
  30. <h2>
  31. Activity Title
  32. </h2>
  33. <span>2/4</span>
  34. <div class="progress">
  35. <div class="progress__complete"></div>
  36. </div>
  37. </li>
  38. <li>
  39. <h2>
  40. Activity Title
  41. </h2>
  42. <span>2/4</span>
  43. <div class="progress">
  44. <div class="progress__complete"></div>
  45. </div>
  46. </li>
  47. </ul>
  48. </div>
  49. </div>
  50. <div class="response">
  51. <div class="response__number">
  52. 1
  53. </div>
  54. <h1 class="response__title">
  55. Coffee emporium avondale humid german rivertown vine street findlay market historic architecture?
  56. </h1>
  57. <div class="post-group">
  58. <div class="post">
  59. <div class="post__avatar"></div>
  60. <h3 class="post__author">
  61. Lester McTester
  62. </h3>
  63. <h4 class="post__timestamp">
  64. Oct 13 at 8:51pm
  65. </h4>
  66. <p class="post__body">
  67. 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.
  68. </p>
  69. <div class="post__actions">
  70. <div class="button button--approve">
  71. <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
  72. </div>
  73. <div class="button button--deny">
  74. <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
  75. </div>
  76. <div class="button button--fill comment-trigger">
  77. <span>Comment...</span>
  78. </div>
  79. <div class="button button--flag">
  80. <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
  81. </div>
  82. <div class="post__comments">
  83. <div class="comment-group">
  84. <div class="post">
  85. <div class="post__avatar comment__avatar"></div>
  86. <h3 class="post__author">
  87. Lester McTester
  88. </h3>
  89. <h4 class="post__timestamp">
  90. Oct 13 at 8:51pm
  91. </h4>
  92. <p class="post__body">
  93. 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.
  94. </p>
  95. </div>
  96. <div class="post">
  97. <div class="post__avatar comment__avatar"></div>
  98. <h3 class="post__author">
  99. Lester McTester
  100. </h3>
  101. <h4 class="post__timestamp">
  102. Oct 13 at 8:51pm
  103. </h4>
  104. <p class="post__body">
  105. 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.
  106. </p>
  107. </div>
  108. </div>
  109. <div class="comment-form">
  110. <div class="comment-form__avatar"></div>
  111. <textarea></textarea>
  112. <div class="comment-form__actions">
  113. <div class="button button--light cancel">
  114. Cancel
  115. </div>
  116. <div class="button button--confirm">
  117. Comment
  118. </div>
  119. </div>
  120. </div>
  121. </div>
  122. </div>
  123. </div>
  124. <div class="post">
  125. <div class="post__avatar"></div>
  126. <h3 class="post__author">
  127. Lester McTester
  128. </h3>
  129. <h4 class="post__timestamp">
  130. Oct 13 at 8:51pm
  131. </h4>
  132. <p class="post__body">
  133. 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.
  134. </p>
  135. <div class="post__actions">
  136. <div class="button button--approve">
  137. <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
  138. </div>
  139. <div class="button button--deny">
  140. <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
  141. </div>
  142. <div class="button button--fill comment-trigger">
  143. <span>Comment...</span>
  144. </div>
  145. <div class="button button--flag">
  146. <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
  147. </div>
  148. <div class="post__comments">
  149. <div class="comment-group">
  150. <div class="post">
  151. <div class="post__avatar comment__avatar"></div>
  152. <h3 class="post__author">
  153. Lester McTester
  154. </h3>
  155. <h4 class="post__timestamp">
  156. Oct 13 at 8:51pm
  157. </h4>
  158. <p class="post__body">
  159. 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.
  160. </p>
  161. </div>
  162. <div class="post">
  163. <div class="post__avatar comment__avatar"></div>
  164. <h3 class="post__author">
  165. Lester McTester
  166. </h3>
  167. <h4 class="post__timestamp">
  168. Oct 13 at 8:51pm
  169. </h4>
  170. <p class="post__body">
  171. 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.
  172. </p>
  173. </div>
  174. </div>
  175. <div class="comment-form">
  176. <div class="comment-form__avatar"></div>
  177. <textarea></textarea>
  178. <div class="comment-form__actions">
  179. <div class="button button--light cancel">
  180. Cancel
  181. </div>
  182. <div class="button button--confirm">
  183. Comment
  184. </div>
  185. </div>
  186. </div>
  187. </div>
  188. </div>
  189. </div>
  190. <div class="post">
  191. <div class="post__avatar"></div>
  192. <h3 class="post__author">
  193. Lester McTester
  194. </h3>
  195. <h4 class="post__timestamp">
  196. Oct 13 at 8:51pm
  197. </h4>
  198. <p class="post__body">
  199. 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.
  200. </p>
  201. <div class="post__actions">
  202. <div class="button button--approve">
  203. <i class="fa fa-thumbs-o-up"></i><i class="fa fa-thumbs-up solid"></i>
  204. </div>
  205. <div class="button button--deny">
  206. <i class="fa fa-thumbs-o-down"></i><i class="fa fa-thumbs-down solid"></i>
  207. </div>
  208. <div class="button button--fill comment-trigger">
  209. <span>Comment...</span>
  210. </div>
  211. <div class="button button--flag">
  212. <i class="fa fa-comment-o"></i><i class="fa fa-comment solid"></i>2
  213. </div>
  214. <div class="post__comments">
  215. <div class="comment-group">
  216. <div class="post">
  217. <div class="post__avatar comment__avatar"></div>
  218. <h3 class="post__author">
  219. Lester McTester
  220. </h3>
  221. <h4 class="post__timestamp">
  222. Oct 13 at 8:51pm
  223. </h4>
  224. <p class="post__body">
  225. 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.
  226. </p>
  227. </div>
  228. <div class="post">
  229. <div class="post__avatar comment__avatar"></div>
  230. <h3 class="post__author">
  231. Lester McTester
  232. </h3>
  233. <h4 class="post__timestamp">
  234. Oct 13 at 8:51pm
  235. </h4>
  236. <p class="post__body">
  237. 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.
  238. </p>
  239. </div>
  240. </div>
  241. <div class="comment-form">
  242. <div class="comment-form__avatar"></div>
  243. <textarea></textarea>
  244. <div class="comment-form__actions">
  245. <div class="button button--light cancel">
  246. Cancel
  247. </div>
  248. <div class="button button--confirm">
  249. Comment
  250. </div>
  251. </div>
  252. </div>
  253. </div>
  254. </div>
  255. </div>
  256. </div>
  257. </div>
  258. </div>
  259. </div>

3. Style the forum using the following CSS styles:

  1. @charset "UTF-8";
  2. * {
  3. box-sizing: border-box;
  4. }
  5.  
  6. html {
  7. color: #4d4d4d;
  8. background-color: #ebeff1;
  9. font-family: "Signika";
  10. font-size: 16px;
  11. font-weight: 300;
  12. text-rendering: optimizeLegibility;
  13. -webkit-font-smoothing: antialiased;
  14. }
  15.  
  16. h1 {
  17. font-size: 26px;
  18. font-weight: 700;
  19. }
  20.  
  21. h2 {
  22. font-size: 18px;
  23. font-weight: 400;
  24. }
  25.  
  26. h3 {
  27. font-size: 18px;
  28. font-weight: 700;
  29. }
  30.  
  31. h4 {
  32. font-size: 12px;
  33. font-weight: 400;
  34. color: #89989c;
  35. }
  36.  
  37. ul {
  38. list-style: none;
  39. padding: 0;
  40. margin: 0;
  41. }
  42.  
  43. .comment-form__avatar, .post__avatar {
  44. position: absolute;
  45. top: 15px;
  46. left: 15px;
  47. height: 50px;
  48. width: 50px;
  49. background-color: #89989c;
  50. border-radius: 50%;
  51. }
  52.  
  53. .comment-form .comment-form__actions .button {
  54. position: relative;
  55. display: inline-block;
  56. width: initial;
  57. height: 35px;
  58. padding: 0 10px;
  59. margin-left: 15px;
  60. background-color: white;
  61. color: #4ab2d9;
  62. line-height: 35px;
  63. font-weight: 400;
  64. text-align: center;
  65. border-radius: 2px;
  66. cursor: pointer;
  67. border: 1px solid #4ab2d9;
  68. -webkit-transition: all 0.1s;
  69. -o-transition: all 0.1s;
  70. transition: all 0.1s;
  71. }
  72. .comment-form .comment-form__actions .button:hover {
  73. background-color: #4ab2d9;
  74. color: #FFF;
  75. }
  76.  
  77. .comment-form, .panel {
  78. position: relative;
  79. padding: 15px;
  80. background-color: #FFF;
  81. border-radius: 2px;
  82. box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  83. }
  84.  
  85. .container {
  86. width: 90%;
  87. max-width: 900px;
  88. margin: 50px auto 100px;
  89. }
  90.  
  91. .response-group {
  92. position: relative;
  93. width: 100%;
  94. padding: 100px 15px 15px;
  95. background-color: #fff;
  96. border-radius: 2px;
  97. box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  98. }
  99. .response-group > header {
  100. position: absolute;
  101. top: 0;
  102. left: 0;
  103. right: 0;
  104. padding: 5px 15px;
  105. background-color: rgba(255, 255, 255, 0.75);
  106. border-radius: 2px;
  107. box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  108. z-index: 100;
  109. }
  110. .response-group > header i {
  111. margin: 0 10px 0 20px;
  112. }
  113. .response-group > header .header-dropdown-trigger {
  114. border: 1px solid transparent;
  115. padding: 10px;
  116. border-radius: 2px;
  117. cursor: pointer;
  118. }
  119. .response-group > header .header-dropdown-trigger:after {
  120. content: "";
  121. font-family: "FontAwesome";
  122. font-size: 0.5em;
  123. line-height: 2.5;
  124. vertical-align: top;
  125. margin-left: 5px;
  126. }
  127. .response-group > header .header-dropdown-trigger:hover, .response-group > header .header-dropdown-trigger.active {
  128. border: 1px solid #cdd7dc;
  129. }
  130. .response-group > .header-dropdown {
  131. display: none;
  132. position: relative;
  133. top: -38px;
  134. left: -16px;
  135. width: calc(100% + 32px);
  136. padding: 15px 1px;
  137. background: #ebeff1;
  138. }
  139. .response-group > .header-dropdown.expand {
  140. display: block;
  141. }
  142. .response-group > .header-dropdown ul {
  143. margin: -15px;
  144. }
  145. .response-group > .header-dropdown li {
  146. padding: 1em 15px;
  147. cursor: pointer;
  148. border-bottom: 1px solid #ebeff1;
  149. }
  150. .response-group > .header-dropdown li h2 {
  151. display: inline-block;
  152. margin: 0;
  153. }
  154. .response-group > .header-dropdown li:hover h2 {
  155. font-weight: 700;
  156. }
  157. .response-group > .header-dropdown li span {
  158. float: right;
  159. margin-left: 15px;
  160. line-height: 1.25;
  161. }
  162. .response-group > .header-dropdown .progress {
  163. float: right;
  164. width: 50%;
  165. margin: 0.25em 0;
  166. }
  167.  
  168. .progress {
  169. position: relative;
  170. width: 100%;
  171. height: 0.75em;
  172. border-radius: 2px;
  173. background-color: #ebeff1;
  174. box-shadow: 0 1px 1px rgba(0, 0, 0, 0.1) inset;
  175. }
  176.  
  177. .progress__complete {
  178. position: absolute;
  179. top: 0;
  180. width: 50%;
  181. height: 0.75em;
  182. background-color: #5fbc71;
  183. border-radius: 2px;
  184. box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  185. }
  186.  
  187. .response {
  188. position: relative;
  189. }
  190.  
  191. .response__number {
  192. position: absolute;
  193. width: 2rem;
  194. height: 2rem;
  195. line-height: 1.8rem;
  196. font-size: 1.2em;
  197. font-weight: 700;
  198. text-align: center;
  199. color: #89989c;
  200. border: 2px solid #cdd7dc;
  201. border-radius: 50%;
  202. }
  203.  
  204. .response__title {
  205. margin-left: 3.25rem;
  206. margin-bottom: 50px;
  207. }
  208.  
  209. .post-group {
  210. margin-left: 3.5rem;
  211. }
  212.  
  213. .post {
  214. position: relative;
  215. padding: 15px 15px 0 80px;
  216. margin-bottom: 50px;
  217. border: 1px solid #ebeff1;
  218. border-bottom: none;
  219. box-shadow: 0 2px 1px rgba(0, 0, 0, 0.15);
  220. }
  221.  
  222. .post__author {
  223. margin-top: 5px;
  224. margin-bottom: 5px;
  225. }
  226.  
  227. .post__timestamp {
  228. margin-top: 0;
  229. }
  230.  
  231. .post__actions {
  232. height: 40px;
  233. width: calc(100% + 95px);
  234. margin-left: -80px;
  235. background-color: #ebeff1;
  236. border-top: 1px solid #ebeff1;
  237. }
  238. .post__actions .button {
  239. float: left;
  240. height: 40px;
  241. width: 40px;
  242. line-height: 40px;
  243. text-align: center;
  244. vertical-align: top;
  245. border-right: 1px solid #cdd7dc;
  246. }
  247. .post__actions .button i.solid {
  248. display: none;
  249. }
  250. .post__actions .button:not(.comment):active i {
  251. transform: scale(1.2);
  252. }
  253. .post__actions .button:not(.comment-trigger):hover, .post__actions .button:not(.comment-trigger).active {
  254. background-color: #FFF;
  255. cursor: pointer;
  256. }
  257. .post__actions .button:not(.comment-trigger):hover i.solid, .post__actions .button:not(.comment-trigger).active i.solid {
  258. display: inline-block;
  259. }
  260. .post__actions .button:not(.comment-trigger):hover i:not(.solid), .post__actions .button:not(.comment-trigger).active i:not(.solid) {
  261. display: none;
  262. }
  263. .post__actions .button:not(.comment-trigger):hover.button--approve, .post__actions .button:not(.comment-trigger).active.button--approve {
  264. color: #5fbc71;
  265. }
  266. .post__actions .button:not(.comment-trigger):hover.button--deny, .post__actions .button:not(.comment-trigger).active.button--deny {
  267. color: #f26f54;
  268. }
  269. .post__actions .button--flag {
  270. width: 60px;
  271. border-right: none;
  272. font-weight: 400;
  273. }
  274. .post__actions .button--flag i {
  275. margin-right: 5px;
  276. }
  277. .post__actions .button--fill {
  278. width: calc(100% - 140px);
  279. padding: 0 10px;
  280. text-align: left;
  281. font-size: 16px;
  282. font-weight: 400;
  283. color: #89989c;
  284. }
  285.  
  286. .post__comments {
  287. display: none;
  288. padding: 15px;
  289. }
  290.  
  291. .comment-group {
  292. padding-bottom: 15px;
  293. }
  294. .comment-group .post {
  295. padding: 15px 15px 0 65px;
  296. margin-bottom: 15px;
  297. box-shadow: none;
  298. }
  299. .comment-group .post__avatar {
  300. height: 35px;
  301. width: 35px;
  302. }
  303.  
  304. .comment-form {
  305. height: 100%;
  306. padding: 15px 15px 15px 65px;
  307. }
  308. .comment-form textarea {
  309. width: 100%;
  310. height: 4em;
  311. margin-bottom: 10px;
  312. font-size: 16px;
  313. border: 1px solid #cdd7dc;
  314. border-radius: 2px;
  315. box-shadow: 0 1px 1px #ebeff1 inset;
  316. }
  317. .comment-form textarea:focus {
  318. outline: none;
  319. }
  320.  
  321. .comment-form__avatar {
  322. height: 35px;
  323. width: 35px;
  324. }
  325.  
  326. .comment-form .comment-form__actions {
  327. text-align: right;
  328. }
  329. .comment-form .comment-form__actions .button {
  330. float: none;
  331. }
  332. .comment-form .comment-form__actions .button--confirm {
  333. border-color: #5fbc71;
  334. color: #5fbc71;
  335. }
  336. .comment-form .comment-form__actions .button--confirm:hover {
  337. background-color: #5fbc71;
  338. color: #FFF;
  339. }
  340. .comment-form .comment-form__actions .button--light {
  341. border-color: transparent;
  342. color: #89989c;
  343. }
  344. .comment-form .comment-form__actions .button--light:hover {
  345. background-color: #89989c;
  346. color: #FFF;
  347. }
  348.  
  349. .post--commenting .post__actions {
  350. height: initial;
  351. }
  352. .post--commenting .button.comment-trigger span {
  353. display: none;
  354. }
  355. .post--commenting .post__comments {
  356. display: block;
  357. margin-top: 40px;
  358. border-top: 1px solid #cdd7dc;
  359. }

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.

  1. $( ".header-dropdown-trigger" ).click(function() {
  2. $( this ).toggleClass( "active" );
  3. $( ".header-dropdown" ).toggleClass( "expand" );
  4. });
  5.  
  6. $( ".header-dropdown li" ).click(function() {
  7. $( ".header-dropdown-trigger" ).removeClass( "active" );
  8. $( ".header-dropdown" ).removeClass( "expand" );
  9. });
  10.  
  11. $( ".button--approve" ).click(function() {
  12. $( this ).toggleClass( "active" );
  13. $( this ).siblings( '.button--deny' ).removeClass( "active" );
  14. });
  15.  
  16. $( ".button--deny" ).click(function() {
  17. $( this ).toggleClass( "active" );
  18. $( this ).siblings( '.button--approve' ).removeClass( "active" );
  19. });
  20.  
  21. $( ".comment-trigger" ).click(function() {
  22. $( this ).parent().parent().toggleClass( "post--commenting" );
  23. });
  24.  
  25. $( ".button--flag" ).click(function() {
  26. $( this ).parent().parent().toggleClass( "post--commenting" );
  27. });
  28.  
  29.  
  30. $( ".button--confirm" ).click(function() {
  31. $( this ).parent().parent().parent().parent().parent().toggleClass( "post--commenting" );
  32. });
  33.  
  34. $( ".button.cancel" ).click(function() {
  35. $( this ).parent().parent().parent().parent().parent().toggleClass( "post--commenting" );
  36. });

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